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 に答える