0

I have created a directive in which i am parsing a variable "count". In my page there is a dropdown and "count" gets updated whenever dropdown value is changed. I have created a directive to show "count". How can i update the directive whenever dropdown value is changed.

Code:

<stats count="{{self.shortenedCountArray[2].orignalCount}}"></stats>

Directive code:

(function() {
    'use strict';

    angular
       .module('app.pages')
       .directive('stats', stats);
   
       stats.$inject = [ '$rootScope']

   function stats( $rootScope) {
       return {
           restrict: 'E',
           scope: {},
           templateUrl: 'k2-modules/js/directives/templates/statsTemplate.html',
           link: (scope, element, attrs) => {
            scope.count = attrs.count;
           }
       }
   }
   
})();

Any help will be appreciated.

1 Answer 1

0
  • Watchers requires some time so if you dont want to next cycle/trigger use $apply

  • and adding timeout clasure may need at some situations.

    link: (scope, element, attrs) => {
      setTimeout ... if needed
       scope.$apply(function () {
        scope.count = attrs.count;
       }); 
    
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.