Angular2 - Materialise - 动态图标

时间:2016-08-18 20:05:33

标签: angular icons materialize

在angular2中我使用Materialise.css,我希望图标依赖于我模型中的值。

<ul>
  <li *ngFor="let tab of tabs" 
   [class.active]="(tab.id == active)" 
   (click)="go(tab.id)">
     <a href="#">
       <i class="material-icons left">{{complete(tab.id)}}</i>
       {{tab.name}}
     </a>
  </li>
</ul>

public tabs = [
  {id: "great", name: "I'm great"},
  {id: "personal", name: "Persoonlijk"},
  {id: "identity", name: "Identiteit"},
  {id: "prefs", name: "Voorkeuren"},
  {id: "available", name: "Beschikbaar"}];

&#34;活跃&#34;上课和&#34;去&#34;方法工作正常,(荷兰语)标签显示正确,但在我的方法&#34;完成&#34;我得到了#34;未定义&#34;作为&#34; tabid&#34;的价值。

complete(tabid) {
  console.log(tabid);
  return (this.candidate && this.candidate.complete[tabid]) ? "done" : "crop_square"
}

任何指针都是受欢迎的。

1 个答案:

答案 0 :(得分:0)

而不是

{{complete(tab.id)}}

试试这个:

{{(candidate && candidate.complete[tab.id]) ? "done" : "crop_square"}}