我试图在角4中使用带*ngif和*ngfor的多重绑定,但有一个错误:
ERROR IMAGE
代码:
<agm-map *ngFor="let m of dataBikes" [latitude]="lat" [longitude]="lng">
<agm-marker *ngFor="let o of m" [latitude]="o.latitude" [longitude]="o.longitude" iconUrl='../../assets/img/icon-pin.png' *ngIf="(o.breakdown == false || o.on_service == false)" iconUrl='../../assets/img/pin-maintenance.png' ></agm-marker>
</agm-map>
我也试过这段代码,但也有错误:
<agm-map *ngFor="let m of dataBikes" [latitude]="lat" [longitude]="lng">
<agm-marker *ngFor="let o of m" [latitude]="o.latitude" [longitude]="o.longitude" iconUrl='../../assets/img/icon-pin.png' *ngIf="(!o.breakdown || !o.on_service )" iconUrl='../../assets/img/pin-maintenance.png' ></agm-marker>
</agm-map>
最佳答案
意味着不能在同一个元素上使用两个结构指令-前缀*
的指令。像这样把他们分开
<agm-marker *ngFor="let o of m" [latitude]="o.latitude" [longitude]="o.longitude" [iconUrl]='(o.breakdown == false || o.on_service == false) ? "../../assets/img/icon-pin.png" : "../../assets/img/pin-maintenance.png"'>
</agm-marker>