Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/428.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.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_Angularjs Scope - Fatal编程技术网

Javascript 手表不触发

Javascript 手表不触发,javascript,angularjs,angularjs-directive,angularjs-scope,Javascript,Angularjs,Angularjs Directive,Angularjs Scope,我们有一个控制器和一个指令。在控制器的$scope中有模块数组,其中包含一些对象 $scope.modules = [ {title: 'demo'}, {title: 'demo 2'}, {title: 'demo 3'}, ]; 我创建的指令如下: var popup = angular.element('<module-popup module="module"></module-popup>'); $compile(popup)($scope

我们有一个控制器和一个指令。在控制器的$scope中有
模块
数组,其中包含一些对象

$scope.modules = [
   {title: 'demo'},
   {title: 'demo 2'},
   {title: 'demo 3'},
];
我创建的指令如下:

var popup = angular.element('<module-popup module="module"></module-popup>');
$compile(popup)($scope);
当页面加载时,我在控制台中看到:
控制器已更改

但当我试图手动更改这些值时,控制台中没有记录,但在屏幕上我看到了正确的值

<h2>{{ module.title }}</h2>
{{module.title}
$scope.$apply()
引发错误


我做错了什么?谢谢

您正在观看标题,但标题不在您的范围内,您尝试观看的范围是modules.title或modules

  $scope.$watch('modules', function() {
        console.log('Controller changed');
    }, true);

您正在观看标题,但它不在您的范围内,您尝试观看的范围是modules.title或modules

  $scope.$watch('modules', function() {
        console.log('Controller changed');
    }, true);

您正在观看标题,但它不在您的范围内,您尝试观看的范围是modules.title或modules

  $scope.$watch('modules', function() {
        console.log('Controller changed');
    }, true);

您正在观看标题,但它不在您的范围内,您尝试观看的范围是modules.title或modules

  $scope.$watch('modules', function() {
        console.log('Controller changed');
    }, true);

可能会在看不到更多上下文的情况下努力帮助他人。可能会在看不到更多上下文的情况下努力帮助他人。可能会在看不到更多上下文的情况下努力帮助他人。可能会在看不到更多上下文的情况下努力帮助他人。