I am starting to shift controller syntax in my router code, as in the following:
url: '/myRoute',
config: {
templateUrl: 'app/my.html',
controller: 'MyController',
controllerAs: 'vm',
title: 'avengers'
}
However one thing I can not find to replace is the ng-init function, often I require a function on init to be called that will either retrieve data or in other cases just required to run so it may perform some arbitrary functions.
I know there is a 'resolve' function but is there something more like an ng-init where I can say, run this controller function on load/transition?
The answer is NO.
And also, please, check the doc to adjust the over-all usage of the ngInit
:
The ngInit directive allows you to evaluate an expression in the current scope.
The only appropriate use of
ngInit
is for aliasing special properties ofngRepeat
, as seen in the demo below. Besides this case, you should use controllers rather thanngInit
to initialize values on a scope.