0

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.

3
  • 3
    So why use ng-init at 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? Commented Jan 23, 2014 at 11:52
  • stackoverflow.com/questions/16150289/… Commented Jan 23, 2014 at 11:55
  • @Stewie, you are right, your comment helped me solve my problem. Thanks! Commented Jan 23, 2014 at 16:22

1 Answer 1

0

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 i.e.

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

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.