Why is the variable set in ng-init undefined in $scope in AngularJS? -


i have variable i'm setting in view ng-init trying access in controller. when try access however, i'm getting undefined.

relevant pieces of code:

my view:

<div ng-controller="myctrl">   <div ng-init="pagetitle = 'kittens'">   </div> </div> 

my controller:

var myctrl;  myctrl = function($scope) {   return console.log($scope.pagetitle); }; 

jsfiddle

what missing here?

wait until variable init.

$scope.$watch('pagetitle', function () {     console.log($scope.pagetitle);  }); 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -