Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 尝试在范围隔离指令中运行绑定方法_Javascript_Angularjs_Angularjs Directive - Fatal编程技术网

Javascript 尝试在范围隔离指令中运行绑定方法

Javascript 尝试在范围隔离指令中运行绑定方法,javascript,angularjs,angularjs-directive,Javascript,Angularjs,Angularjs Directive,为什么这不起作用 index.html <div ng-controller="mainController"> <sun external-fct="changeValue(internalValue)"></sun> </div> directions.js controllers.controller('mainController', ['$scope', function ($scope) { $scope.chan

为什么这不起作用


index.html

<div ng-controller="mainController">
    <sun external-fct="changeValue(internalValue)"></sun>
</div>
directions.js

controllers.controller('mainController', ['$scope', function ($scope) {

    $scope.changeValue = function (newValue) {
        $scope.value = newValue;
    }

    $scope.$watch('value', function (n, o) {
        if (n !== o)
            alert('the value has changed to ' + n);
    });

}]);
directives.directive('sun', function () { return {

    scope: {
        fct: '&externalFct'
    },

    template: '<button>click me</button>',

    link: function (scope, element, attrs) {

        element.on('click', function (e) {
            scope.fct({
                internalValue : 'test'
            })
        });
    }
}});
指令('sun',函数(){return{ 范围:{ fct:“&外部fct” }, 模板:“单击我”, 链接:函数(范围、元素、属性){ 元素上('click',函数(e){ scope.fct({ 内在价值:“测试” }) }); } }}); 当我单击
时,指令的外部作用域不会
$watch
更改的值

WWHOOPS!我只是忘了在单击时运行
$digest()