Javascript AngularJs-屏蔽中断ng控制器
我对angular有着深刻的理解,我无法理解我做错了什么 我有一个被ng控制器包围的指令Javascript AngularJs-屏蔽中断ng控制器,javascript,angularjs,angularjs-directive,controller,angularjs-ng-transclude,Javascript,Angularjs,Angularjs Directive,Controller,Angularjs Ng Transclude,我对angular有着深刻的理解,我无法理解我做错了什么 我有一个被ng控制器包围的指令 KApp.directive("testdirective", function ($compile) { return { restrict: 'E', transclude: true, scope: { test:"=" },
KApp.directive("testdirective", function ($compile)
{
return {
restrict: 'E',
transclude: true,
scope: {
test:"="
},
template: "<div>\
<div style='width:120px'>\
{{test}}\
</div>\
<div ng-transclude>\
</div>\
</div>"
};
});
KApp.controller('testCtrl', function ($scope)
{
$scope.someText ="not important"
$scope.pass = "1234";
$scope.showPass = function()
{
//why the $scope.pass not updated via ng-model???
alert($scope.pass)
}
});
KApp.directive(“testdirective”),函数($compile)
{
返回{
限制:'E',
是的,
范围:{
测试:“=”
},
模板:“\
\
{{test}}\
\
\
\
"
};
});
KApp.controller('testCtrl',函数($scope)
{
$scope.someText=“不重要”
$scope.pass=“1234”;
$scope.showPass=函数()
{
//为什么$scope.pass没有通过ng模型更新???
警报($scope.pass)
}
});
HTML
<body ng-app="mainModule" ng-controller="appCtrl">
<div ng-controller="tsetCtrl">
<testdirective test="someText">
<button style='width:120px' ng-click='showPass()'>
Click me
</button>
<input ng-model='pass' style='width:120px'>
</testdirective>
</div>
点击我
ng model=“pass”
绑定到$scope.pass=“1234”代码>并应由用户进行更新
我的问题:
$scope.pass
没有被视图更新,为什么
这是完整的演示-
只需单击“单击我”按钮并查看结果。showPass()
和ng model
在输入值更改后参考不同的范围。请参阅以获得更深入的解释。值1234是基本值,因此在内部作用域中创建了第二个过程
,它从外部作用域(=控制器)重写1234值。请试一试。