简体   繁体   中英

How can I execute a JS function before ng-init is called in AngularJS?

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 .

this is really bad approach but this should work.

  1. Write your method in another script file and include it before you are putting ng-init.
  2. Wrap it up as self executing function ie

    (function(){ //Your code })();

If you want to get the results, expose a global variable from the script file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM