0

how to initialize value inside run block in angular.js

directives.value("value1","test1");

directives.run(function(value1){
    value1="test2";
})

Is this possible

1
  • Did this work for you? Commented Jan 31, 2018 at 7:00

1 Answer 1

1

If you are using a primitive as the value, you will only get a copy of that injected into the run function and you will not be able to replace the original one.

Use an object instead:

directives.value("value1", { something: "test1" });

directives.run(function(value1){
    value1.something = "test2";
})
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.