简体   繁体   中英

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

 <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? 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; we can see value is getting updated but not in the text box.

Why don't you just bind directly to post.id? If it has a value, it will bind it to the value property of the text box.

Also, make sure you are using correct markup (input tag) and using the correct directives (ng-init). And I'm pretty sure to do not want to repeat the ul tag, but the items inside of it.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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