Angular 2 App中字符串插值的即时评估

时间:2022-08-03 21:44:57

I am trying to use an *ngIf in my Angular 2 app, and have it evaluate whether a string interpolated value is set to a certain parameter. I've tried several syntactical constructions, but so far they all return errors. I've tried, for instance, something like this:

我试图在我的Angular 2应用程序中使用* ngIf,并让它评估字符串插值是否设置为某个参数。我已经尝试了几种语法结构,但到目前为止它们都返回了错误。我试过,例如,这样的事情:

<div *ngIf="{{info.status === 'consult'}}">

I've also tried:

我也尝试过:

<div *ngIf="[{{info.status === 'consult'}}]">

And...

<div *ngIf="{{info.status}} === 'consult'">

What is the correct way to pass in this string interpolated value and have it evaluated on the fly?

传递此字符串插值并正确评估它的正确方法是什么?

1 个解决方案

#1


2  

When you are inside an Angular2 directive you do not need to put the interpolation syntax. Do this

当您在Angular2指令中时,您不需要插入插值语法。做这个

<div *ngIf="info?.status === 'consult'">

#1


2  

When you are inside an Angular2 directive you do not need to put the interpolation syntax. Do this

当您在Angular2指令中时,您不需要插入插值语法。做这个

<div *ngIf="info?.status === 'consult'">