javascript - Angular Directives - Knowing when the object bound to an attribute is changed -
Assuming that I have an opportunity that is about the currently selected user on the left and the users on detailed information Displays a list.
I make a user's description element directive in two ways binding and ends with the instructional object that looks something like this:
{restrict: 'E', scope: {User: "="}, templateUrl: '...', Controller: function () {... elided ...}}
In the basic HTML, I use this as the command:
& lt; User-Detail User = "currentUser" & gt; & Lt; / User-Detail & gt;
As the user selection changes to the left, the currentUser property is updated, which causes the user property in pointers to point to another object. In the user's description, the information is well reproduced in HTML, but
(here is the question)
assuming that some of my What is the small thing I should do to work when the display user changes, maybe a JSON string should be parsed in the object.
How do I know that the bound object has changed (and I need to re-parse)?
I have tried:
- Check out $ scope.user
- $ attr, 'user' is seeing
Administrators and link functions appear to call only once.
Somewhere I should remember something It does not seem that should be away from the beaten path.
You should use the link and then see user
like this:
{restrict: 'e', radius: {user: "="}, templateUrl: '...', link: function (scope) {scope. $ Watch ('user', function (value) {// your belongings here}); }}
You can also see the user with the function:
area. $ Watch (function () {retrun scope.user;}, function (value) {// your belongings here});
But then it will only be updated on paycheck. You can search or search as angularjs digest cycle .
Edit:
I forgot the scope since the argument I just sticks.
Comments
Post a Comment