0

为什么 $scope.watch 不能与“模型”一起使用? http://jsfiddle.net/lesouthern/8PUtP/5/

.directive('testDirective',function() {
    return {
        restrict : 'A',
        scope : {
            model : '=ngModel'
        },
        link : function($scope,$element,$attrs) {
            $scope.$watch('model',function(x) {
                console.log('this is model: ' + x);
            });
        }
    }
});
4

1 回答 1

0

请看这个问题。这是您更正的代码:

return {
    restrict : 'A',
    link : function($scope, $element, $attrs) {
        $scope.$watch($attrs.ngModel, function(x) {
            console.log('this is model: ' + x);
        });
    }
}
于 2013-06-18T21:55:32.007 回答