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); }; what missing here?
wait until variable init.
$scope.$watch('pagetitle', function () { console.log($scope.pagetitle); });
Comments
Post a Comment