*ngIf=item.activityStatus!=("Done") 作为 angular2 条件可见性
*ngIf=item.activityStatus!=("Done") as angular2 conditional visibility
我想根据项目的值切换按钮的可见性
这是我的代码:
<tbody>
<tr *ngFor="let item of statusConfig | slice:0:9; let i = index;" >
<td class="col-md-1">
{{item.id}}
</td>
<td class="col-md-3">
{{item.activityName}}
</td>
<td class="col-md-2">
{{item.activityStatus}}
</td>
<td class="col-md-3">
{{item.activityDateEpoch | date: 'yyyy-MM-dd HH:mm:ss'}}
</td>
<td class="col-md-3">
<button *ngIf=item.activityStatus!=("Done") type="button" class="btn btn-primary" (click)="saveStatus(item.id, i)">Mark as done</button>
</td>
</tr>
</tbody>
为什么这是一个语法错误,我应该如何解决这个问题?
directive_normalizer.js:82 Uncaught Error: Template parse errors:
Unexpected closing tag "button" ("tyStatus!="Done" type="button" class="btn btn-primary" (click)="saveStatus(item.id, i)">Mark as done[ERROR ->]</button>
</td>
"): ReportComponent@45:145
和
activityStatus = "Done" for now
应该是,
*ngIf="(item.activityStatus!='Done')"
我很震惊你在一行代码中犯了多少错误。 :-)
首先:NgIf
指令接受string
作为表达式值,这意味着它必须具有以下形式:
*ngIf="expression here"
其次:不能两次使用"
,如果要在"
中使用string
,应该使用然后单引号 ('
)
第三:不需要括号:("Done")
无论如何,你的表情应该是这样的:
*ngIf="item.activityStatus != 'Done'"
您可以阅读有关 NgIf
指令的更多信息 here。
我想根据项目的值切换按钮的可见性
这是我的代码:
<tbody>
<tr *ngFor="let item of statusConfig | slice:0:9; let i = index;" >
<td class="col-md-1">
{{item.id}}
</td>
<td class="col-md-3">
{{item.activityName}}
</td>
<td class="col-md-2">
{{item.activityStatus}}
</td>
<td class="col-md-3">
{{item.activityDateEpoch | date: 'yyyy-MM-dd HH:mm:ss'}}
</td>
<td class="col-md-3">
<button *ngIf=item.activityStatus!=("Done") type="button" class="btn btn-primary" (click)="saveStatus(item.id, i)">Mark as done</button>
</td>
</tr>
</tbody>
为什么这是一个语法错误,我应该如何解决这个问题?
directive_normalizer.js:82 Uncaught Error: Template parse errors:
Unexpected closing tag "button" ("tyStatus!="Done" type="button" class="btn btn-primary" (click)="saveStatus(item.id, i)">Mark as done[ERROR ->]</button>
</td>
"): ReportComponent@45:145
和
activityStatus = "Done" for now
应该是,
*ngIf="(item.activityStatus!='Done')"
我很震惊你在一行代码中犯了多少错误。 :-)
首先:NgIf
指令接受string
作为表达式值,这意味着它必须具有以下形式:
*ngIf="expression here"
其次:不能两次使用"
,如果要在"
中使用string
,应该使用然后单引号 ('
)
第三:不需要括号:("Done")
无论如何,你的表情应该是这样的:
*ngIf="item.activityStatus != 'Done'"
您可以阅读有关 NgIf
指令的更多信息 here。