I have an ng-init directive defined on my html tag, with it initializing some data. I want a certain JS function to run before this initialization occurs. How can I accomplish this? Basically my objective is to assign the data returned by this function to the variable initialized in ng-init.
1 Answer
this is really bad approach but this should work.
- Write your method in another script file and include it before you are putting ng-init.
Wrap it up as self executing function i.e.
(function(){ //Your code })();
If you want to get the results, expose a global variable from the script file.
ng-initat all? If you have a function that calculates the value of the variable, then why not simply assign the result of that function directly to a scope variable, in the controller itself?