ngFor与ngIf

时间:2017-06-02 15:39:23

标签: javascript angular typescript

<ul class="dropdown-menu" aria-labelledby="selectShop">
    <li *ngFor="let s of i.shops_id">
       <a *ngFor="let shop of shops">
             <span *ngIf="shop._id == s">{{ shop.name }}</span>
       </a>
    </li>
</ul>

它创建了空a标签,但我需要

<ul class="dropdown-menu" aria-labelledby="selectShop">
    <li *ngFor="let s of i.shops_id">
       <a *ngFor="let shop of shops" *ngIf="shop._id == s">
             {{ shop.name }}
       </a>
    </li>
</ul>

此代码抛出错误。

  

core.es5.js:1084 ERROR错误:未捕获(在承诺中):错误:模板   解析错误:在一个元素上不能有多个模板绑定。   只使用一个名为&#39; template&#39;或以*为前缀   (&#34; lledby="selectShop"> <li *ngFor="let s of i.shops_id"><a *ngFor="let shop of shops" [ERROR ->]*ngIf="shop._id == s">{{ shop.name }}</a></li> </ul> </div>&#34):

如何解决此问题?

0 个答案:

没有答案