This plunkr demonstrates a few different scenarios and capabilities when moving data between a model and a directive. Like other places in Angular JS there are quite a number of different approaches that work, which grants a lot of flexibility but also leads to some confusion.
The example uses a simple controller.
he first version of valueDisplay will put the value on the screen, but will never update the screen if the magic value changes. This approach is only reasonable for static data since the directive reads the value directly from the controller’s scope (using the name specified in the attribute), places the value in the element, then never looks back.
The second version of valueDisplay uses a $watch to update the screen as the model value changes. Notice the attribute value (value="magicString") is still working like an expression to retrieve and watch data directly from the controller’s scope.
Your new post is loading...