Javascript 手表不触发
我们有一个控制器和一个指令。在控制器的$scope中有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.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);
可能会在看不到更多上下文的情况下努力帮助他人。可能会在看不到更多上下文的情况下努力帮助他人。可能会在看不到更多上下文的情况下努力帮助他人。可能会在看不到更多上下文的情况下努力帮助他人。