...">

Angular: How to force redirect directive?

HTML:

<div ng-repeat="obj in arr"> <custom-directive status-stored-in="obj"></custom-directive> </div> 

Problem:

I have a built-in page rotation for a lot of obj s. This means that the arr value representing the current obj s page will change. However, the obj in the status-stored-in="obj" not updated with the change.

My current solution is to add ng-if to customDirective , flickering its value back and forth to make it recompile. Is there any other equivalent, more accurate way to handle this?

Edit:

The beginning of the user directive:

 module.directive 'checkbox', (checkboxHooks) -> restrict: 'E' scope: hook: '=' hookedTo: '=' statusStoredIn: '=' templateUrl: 'templates/checkbox.html' link: (scope, element, attr) -> 

The bottom line is that to store the checked status, it needs to get an object. All of this can be found here: [ coffee / js ].

+5
source share
1 answer

Inside the directive links function, you need to look at the status-stored-in for changes, and then recompile it, for example:

  link: function(scope, element) { scope.$watch('statusStoredIn', function() { element.html(statusStoredIn); $compile(element.contents())(scope); }); } 
+5
source

Source: https://habr.com/ru/post/1213601/


All Articles