[英]Angular js $setViewValue doesnt effect the ngModel
我不明白當我調用$ setViewValue函數時,為什么表達式更新而ng模型值卻沒有。
這是the人:
http://plnkr.co/edit/2xdsujEsqDVVXaSPNqYE?p=preview
編碼:
<body ng-controller="MainCtrl">
<input type="text" ng-model="user.name" set-value>
{{user.name}}
<input type="button" value="click" ng-click="change()">
</body>
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.user = {name:'name'};
})
.directive('setValue', function() {
return {
restrict:'A',
require:'ngModel',
link: function(scope,ele, attr, ctrl) {
scope.change = function() {
ctrl.$setViewValue('text');
}
}
}
})
在執行ctrl.$setViewValue('text')
之后,嘗試立即添加ctrl.$render()
ctrl.$setViewValue('text')
。 這將導致UI使用最新的模型更改進行更新。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.