0

このディレクティブでデータ バインディングを機能させることができません。イベントハンドラー内で変数を変更すると、変数が正しくバインドされません。

私は何を間違っていますか?>テストフィドル

var myApp = angular.module('myApp', [])
    .directive('inputTest', function () {
    return {
        restrict: 'E',
        template: '<div class="input-group">\
                    <input type="text" class="form-control" />\
                    <br>child scope: {{myValue}}\
                  </div>',
        scope: {
            myValue: '=',
        },
        link: function (scope, element, attrs) {
            $(element).on('click', function (e) {
                alert('c');
                scope.myValue = 'clicked';
            });
            scope.myValue = 'not clicked';
        },
    };
})

function MyCtrl($scope) {
    $scope.myValue = 'parent value';
}

HTML

<div ng-controller="MyCtrl">parent scope: {{myValue}}
    <input-test my-value="myValue"></input-test>
</div>
4

1 に答える 1