AngularJs不绑定纳克模型NG-检查 [英] AngularJs doesn't bind ng-checked with ng-model
问题描述
我GOOGLE了这一点,并发现,人们不得不这个问题,但我还没有找到任何解决办法。
I have googled this and found out that people had this issue, but I haven't found any solution.
这就是我的code
%section(ng-controller="UserCtrl" ng-init="user_genres=#{preferred_genres}")
%ul
%li(ng:repeat="genre in preferred_genres")
%input(type = "checkbox" ng:model="preferred_genres[genre]" id="genre-{{$index + 1}}" ng-checked="user_genres['{{genre}}']")
%label{:for => "genre-{{$index + 1}}"} {{genre}}
例如,如果一些复选框是由于检查NG-检查前pression是真实的,页面上呈现。我实际上并没有再次点击复选框它。当涉及到控制器,范围似乎忽略已检查,因为NG-检查之一。我该如何让他们很好地同步?
For example if some of the checkboxes are checked due to ng-checked expression is true and on page render. And I didn't actually click the checkbox it again. When it comes to the controller, the scope seems to ignore the one that has been checked because of ng-checked. How do I make them sync nicely?
推荐答案
我不能肯定我明白了真正的问题是什么,但看看这的小提琴是你想要的。 (我获得preferred_genres列表从<一个href=\"http://stackoverflow.com/questions/14225855/how-to-$p$p-select-checkbox-in-angularjs-with-ng-checked\">other帖子。)
I'm not certain I understand what the real problem is, but see if this fiddle is what you want. (I obtained a list of preferred_genres from your other post.)
控制器scope属性 preferred_genres
是基于复选框的状态被更新:
The controller scope property preferred_genres
is being updated based on the checkbox state:
<li ng-repeat="(genre, checked) in preferred_genres">
<input type="checkbox" ng-model="preferred_genres[genre]"
id="genre-{{$index + 1}}">
作为@ dnc253在其他文章中提到,你可能不需要NG-检查,因为每个项目都有自己的NG-模式。
As @dnc253 mentioned in your other post, you probably don't need ng-checked since each item has its own ng-model.
这篇关于AngularJs不绑定纳克模型NG-检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!