我对角度有深刻的理解,我无法理解我做错了什么。
我有一个被 ng-controller 包围的指令。
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)
}
});
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
视图没有更新,为什么?
这是完整的演示 - http://plnkr.co/edit/MsKm0LZtlQ45Yyq5Uw0d?p=preview
只需单击“单击我”按钮并查看结果。