[Angular 2] Interpolation: check object exists

Posted Answer1215

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[Angular 2] Interpolation: check object exists相关的知识,希望对你有一定的参考价值。

In Angular2, sometime we use @Output to pass data to parent component, then parent may pass the data down to another child component.

When you want to display the property of this object, we may need to check whether the object exists or not, otherwise if it not exists, angular2 will throw error.

 

Of course you can predefine object in the controller, or do something like:

<h2>{{thisHero && thisHero.name}}</h2>

Check the object first, then display the name.

 

In angular2 , there is another simple way to do it:

<h2>{{thisHero?.name}}</h2>

THe ? mark tell angular to check whether the object exists, if not, just ingore it

以上是关于[Angular 2] Interpolation: check object exists的主要内容,如果未能解决你的问题,请参考以下文章

组件与模板 显示数据

算法思考Radial basis function interpolation (RBF)插值法

(转)Polynomial interpolation 多项式插值

Inverse Quadratic Interpolation (website)

OpenCV ——双线性插值(Bilinear interpolation)

透视校正插值(Perspective-Correct Interpolation)