Why does the following code not work? I want the $scope.init() function to run on startup. What is the correct way to run code on controller initialization?
app.controller('LoginCtrl', function($scope) {
$scope.init();
$scope.init = function() {
...
};
});
init()after the function?$scope.init()does not exist from where you are calling it. Call it after setting it, i.e. first$scope.init = function...and then$scope.init(). And you may even not need to putinit()in scope, running it inline may suffice.