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

前端 未结 4 1291
难免孤独
难免孤独 2020-12-29 19:58

I have a variable I\'m setting in my view with ng-init which I am then trying to access in my controller. When I try to access it however, I\'m getting an

4条回答
  •  情话喂你
    2020-12-29 20:29

    Wait until the variable is init.

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

提交回复
热议问题