【发布时间】:2013-12-22 10:05:02
【问题描述】:
我有一个适用于复选框的指令,该复选框也有 ng-model。
在链接功能指令中,复选框未获取模型的值。
如果添加超时(不管多长时间,即使是 0 )也是有效的。
我的控制和指令:
var myApp = angular.module("myApp",[])
.directive("checkBox", function($timeout){
return {
restrict: 'A',
link: function (scope, element, attrs, ctrl) {
console.log("Check box is : " + element[0].checked);
scope.message += "Check box is : " + element[0].checked + " , ";
$timeout(function(){
scope.message += "Check box is : " + element[0].checked;
console.log("Check box is : " + element[0].checked);
},0);
}
}
});
function myCtrl($scope){
$scope.checkBoxModel = true;
$scope.message = "";
}
HTML:
<div ng-app="myApp" ng-controller="myCtrl" >
<input type="checkbox" ng-model="checkBoxModel" check-box>
<br/>
{{message}}
</div>
菲德尔-http://jsfiddle.net/myyjL/
提前致谢。
【问题讨论】:
标签: angularjs angularjs-directive