可以宣佈由於在NG-INIT也越來越真實
<!doctype html>
<html ng-app="plunker" >
<head>
<meta charset="utf-8">
<title>AngularJS Plunker</title>
<script>document.write('<base href="' + document.location + '" />');</script>
<link rel="stylesheet" href="style.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angular.js"></script>
<script src="app.js"></script>
</head>
<body ng-controller="MainCtrl" ng-init="testModel['item1']= true">
<label><input type="checkbox" name="test" ng-model="testModel['item1']" /> Testing</label><br />
<label><input type="checkbox" name="test" ng-model="testModel['item2']" /> Testing 2</label><br />
<label><input type="checkbox" name="test" ng-model="testModel['item3']" /> Testing 3</label><br />
<input type="button" ng-click="submit()" value="Submit" />
</body>
</html>
,您可以選擇的第一個對象,並在此同時標出真,假,FLASE
'NG-checked'被計算爲真正的表達。爲了表明'ng-model'沒有鏈接,我在那裏用到了。在啓動控制器的同時,我希望所有的複選框不被選中。經過一些Ajax請求後,我計算'ng-checked'來檢查複選框。這是當我的'ng模型'不更新。 – Abilash
@Abilash你不應該使用'ngChecked'。你的模型很好,你只需要在你的ajax回調中設置'testModel.item1 = true',然後調用'$ scope。$ apply()'來更新你的視圖。 – Langdon
我們只是犯了使用'ng-checked'而不是'ng-model'的錯誤......永遠不會! – g00glen00b