$watch ngModel from inside directive using isolate scope

前端 未结 6 1851
刺人心
刺人心 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:50

    The problem is that you $watching attrs.ngModel which is equal to "myModel". You do not have "myModel" bound in your scope. You want to $watch "model". That is what is bound in the scope of your directive. See http://jsfiddle.net/BtrZH/5/

提交回复
热议问题