admin管理员组文章数量:1289557
I have a list of disabled input field created via ng-repeat Plunker
<ul>
<li ng-repeat="name in names">
<input type="text" disabled value="{{name.item}}"/>
</li>
</ul>
How can I make the first input field not disabled ? Thanks in advance
I have a list of disabled input field created via ng-repeat Plunker
<ul>
<li ng-repeat="name in names">
<input type="text" disabled value="{{name.item}}"/>
</li>
</ul>
How can I make the first input field not disabled ? Thanks in advance
Share Improve this question edited Apr 7, 2015 at 20:54 Martin Thorsen Ranang 2,4151 gold badge29 silver badges43 bronze badges asked Apr 7, 2015 at 20:12 RaihanRaihan 4,0113 gold badges25 silver badges41 bronze badges3 Answers
Reset to default 6You can use ng-disabled and check the ng-repeat directive's $first
variable:
<ul>
<li ng-repeat="name in names">
<input type="text" ng-disabled="!$first" value="{{name.item}}"/>
</li>
</ul>
You could similarly check for $middle
, $last
, $even
, and $odd
. If you use $index
, you can check for arbitrary row indexes.
Since ng-repeat
creates an isolated scope, in the case of a nested ng-repeat
, if you want only the first item in the first parent to be enabled, the relevant code would look like:
<div ng-repeat="item in items">
<ul>
<li ng-repeat="name in names">
<input type="text" ng-disabled="!$parent.$first || !$first" value="{{name.item}}"/>
</li>
</ul>
</div>
where you access the outer scope's $first
(or $index
) variable through the inner ng-repeat
's $parent
variable. I created a fork of your Plunker that shows how this can be done.
You are looking for $index. So, just check if the current $index
is not the first "0th":
<ul>
<li ng-repeat="name in names">
<input type="text" ng-disabled="$index != 0" value="{{name.item}}"/>
</li>
</ul>
This is what you're looking for!
<ul>
<li ng-repeat="name in names">
<input type="text" ng-disabled="!$first" value="{{name.item}}"/>
</li>
</ul>
You can see the documentation for ng-repeat
for more special variables like $first
.
本文标签: javascriptAccess the first item from ngrepeatStack Overflow
版权声明:本文标题:javascript - Access the first item from ng-repeat - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741427245a2378146.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论