简体   繁体   中英

Binding doesn't work in nested elements inside ng-repeat

I have this code:

<div class="list-group">
<a href="#" class="list-group-item" ng-repeat="user in users">
    <h4 class="list-group-item-heading">{{user.FirstName}} {{user.FirstName}}</h4>
    <p class="list-group-item-text">
        <a href="#">{{user.Phone}}</a>
    </p>
</a>

If I use {{user.Phone}} not inside the <a> it works, otherwise it displays nothing and I don't get any error or anything.

You cannot put an <a> tag within an <a> tag. This is against HTML definition.

Try changing your outer <a> tag to a <div> and remove the href attribute.

you have an html error there: a link inside a link. Notice that the user.Phone link is inside the already existing link that you use ng-repeat on:

I would change code to this:

<div href="#" class="list-group-item" ng-repeat="user in users">
    <h4 class="list-group-item-heading">{{user.FirstName}} {{user.FirstName}}</h4>
    <p class="list-group-item-text"><a href="#">{{user.Phone}}</a></p>
</div>

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