$watch ngModel from inside directive using isolate scope

前端 未结 6 1872
刺人心
刺人心 2020-12-08 09:13

I am trying to watch my model value from inside my linking function.

scope.$watch(attrs.ngModel, function() {
       console.log(\"Changed\"); 
    });
         


        
6条回答
  •  轮回少年
    2020-12-08 09:46

    There are 2 ways to do it.

    1) You can use $attrs.[any_attribute] and set on it any listener

    2) You can have isolated scope with 2 ways binding variable and set a listener on it.If you want more,here is a cool article

    http://www.w3docs.com/snippets/angularjs/bind-variable-inside-angularjs-directive-isolated-scope.html

提交回复
热议问题