简体   繁体   English

angularjs在ng-repeat指令中预填充输入文本

[英]angularjs Prepopulate input text inside ng-repeat directive

We have input text to be shown with pre filled values. 我们有要显示的带有预填充值的输入文本。 We are using list using ng-repeat directive 我们正在使用使用ng-repeat指令的列表

 <ul ng-repeat="post in postList>
   <input type="text" ng-model="postid" nginit="postid='{{post.id}}'"></input>
 </ul>

This question AngularJS - Value attribute on an input text box is ignored when there is a ng-model used? 使用ng模型时,此问题AngularJS-输入文本框中的Value属性会被忽略吗? tells to how to prepopulate input text. 告诉您如何预填充输入文本。 But somehow we are finding it difficult using inside dynamic list. 但是以某种方式,我们发现使用内部动态列表很困难。 Can we do like this or there is any better approach? 我们可以这样做吗,还是有更好的方法?

When we this code we dont get any value in the text box but on checking in elements tab of developer console of chrome; 当我们编写此代码时,我们没有在文本框中获得任何值,而是在chrome开发者控制台的签入元素选项卡中; we can see value is getting updated but not in the text box. 我们可以看到值正在更新,但不在文本框中。

Why don't you just bind directly to post.id? 为什么不直接绑定到post.id? If it has a value, it will bind it to the value property of the text box. 如果具有值,它将绑定到文本框的value属性。

Also, make sure you are using correct markup (input tag) and using the correct directives (ng-init). 另外,请确保使用正确的标记(输入标签)和正确的指令(ng-init)。 And I'm pretty sure to do not want to repeat the ul tag, but the items inside of it. 而且我敢肯定,不想重复ul标签,而是重复其中的项目。

<ul>
    <li ng-repeat="post in postList">
        <input type="text" ng-model="post.id"></input>
    </li>
</ul>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM