Javascript 角度指令变量在父作用域中不可用
我目前被一个简单的问题困扰着: 我有一个controller.jsJavascript 角度指令变量在父作用域中不可用,javascript,angularjs,Javascript,Angularjs,我目前被一个简单的问题困扰着: 我有一个controller.js app.controller('WizardCtrl', function ($scope) { $scope.send = function() { console.log($scope.isPasswordChanged) } }); myview.html isPasswordChanged: {{ isPasswordChanged }} <br> <update-password-f
app.controller('WizardCtrl', function ($scope) {
$scope.send = function() {
console.log($scope.isPasswordChanged)
}
});
myview.html
isPasswordChanged: {{ isPasswordChanged }} <br>
<update-password-field is-changed="isPasswordChanged"></update-password-field>
<button ng-click="send()"></button>
因此,在my view.html中,我可以看到“isPasswordChanged”的更改,因为它在我的$scope中,但如果我使用console.log($scope),则“isPasswordChanged”不存在
为什么以及如何让它呈现 我认为您需要在控制器的函数()中包含
$scope
。换言之:
app.controller('WizardCtrl', ['$scope', function ($scope) {
否则我不相信它会起作用。结果可能是我的结构有问题 我变了
is-confirmed="isPasswordConfirmed"
到
“ui”是我在$scope中定义的空对象
以及它的工作原理。我试过一个单独的例子
http://plnkr.co/edit/bkMZTEWgkrmVfxqiYCcB?p=preview
但是它在没有这些更改的情况下工作,它也可能与angular版本不匹配。在调用
发送
函数时,您将控制台.log($scope)
放在哪里了?你能提供工作示例吗?@K.Toress在我的send()函数中,我更新了我的视图。html@Grundy我更新了我的view.htmlI think@Craig有答案我认为应该是app.controller('WizardCtrl',function($scope){..
?不是吗?@K.Toress好的,我已经修好了。@Craig关于这个主题,我可以在我的指令中注入$scope@Craig抱歉,这只是一个例子,但我真正的代码在我的控制器中包含$scope。我刚刚更新了代码。
is-confirmed="ui.isPasswordConfirmed"
http://plnkr.co/edit/bkMZTEWgkrmVfxqiYCcB?p=preview