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的更多相关文章

  1. [Javascript] Keyword 'in' to check prop exists on Object

    function addTo80(n ) { + n; } function memoizedAddTo80 (fn) { let cache = {}; return (n) => { /*k ...

  2. Scala 安装 Exception in thread "main" java.lang.VerifyError: Uninitialized object exists on backward branch 96

    windows下载安装完最新版本的Scala(2.12.4)后,终端如下错误 C:\Users\Administrator>scala -versionException in thread & ...

  3. Error:Uninitialized object exists on backward branch 70 Exception Details:

    网上下载了一个demo,编译出现如下错误: Gradle sync failed: Uninitialized object exists on backward branch 70 Exceptio ...

  4. Angular源代码学习笔记-原创

    时间:2014年12月15日 14:15:10 /** * @license AngularJS v1.3.0-beta.15 * (c) 2010-2014 Google, Inc. http:// ...

  5. angular源码分析:angular中各种常用函数,比较省代码的各种小技巧

    angular的工具函数 在angular的API文档中,在最前面就是讲的就是angular的工具函数,下面列出来 angular.bind //用户将函数和对象绑定在一起,返回一个新的函数 angu ...

  6. [Javascript Crocks] Safely Access Object Properties with `prop`

    In this lesson, we’ll use a Maybe to safely operate on properties of an object that could be undefin ...

  7. What happened when new an object in JVM ?

    原文链接:https://www.javaspring.net/java/what-happened-when-new-an-object-in-jvm I. Introduction As you ...

  8. Angular CLI 升级 6.0 之后遇到的问题

    Angular CLI 1.7.4 在使用 ng build --prod 会构建失败,而 ng build 是正常的.比较好的解决办法是使用 ng build --prod --extract-li ...

  9. Unity Shaderlab: Object Outlines 转

    转 https://willweissman.wordpress.com/tutorials/shaders/unity-shaderlab-object-outlines/ Unity Shader ...

随机推荐

  1. java对象初级知识

    this属于类 方法中没有自己的this指针(本来以为js方法中有,其实并没有里,那是被new出来的function 在声明的时候可以赋初值: int a =12 但不能   int a  ;   a ...

  2. javascript之闭包深入理解(一)

    曾经在开始学习javascript的时候,很是不理解闭包的概念.今天想对它详细的剖析. 在说清楚闭包之前,必须先清楚作用域链. 作用域链 我们知道,执行环境是js中最为重要的一个概念.执行环境定义了变 ...

  3. Zend Studio 8.0.1 新建远程项目无法展示远程项目列表的问题

    PHP的开发工具还是不少的,有用VI,有用eclipse.Netbean.sublime Text,当然用的比较多的还是Zend Studio,这次试用Zend Studio 8.0.1 开发几个PH ...

  4. SAX解析

    SAX解析工具- Sun公司提供的.内置在jdk中.org.xml.sax. 核心的API: SAXParser类: 用于读取和解析xml文件对象 parse(File f, DefaultHandl ...

  5. Hive笔记--配置以及遇到的问题

    ubuntu安装mysql  http://www.2cto.com/database/201401/273423.html Hive安装: http://www.aboutyun.com/forum ...

  6. SwitchySharp怎样设置 ( proxy switch!的设置与使用方法)

    规则列表URL  https://autoproxy-G{过}F{滤}Wlist.googlecode.com/svn/trunk/G{过}F{滤}Wlist.txt 注:不同的代{过}{滤}理  相 ...

  7. 一个简单LINUX程序的逆向

    开始之前的准备: 反汇编:IDA 十六进制编辑器: Hexworkshop LINUX环境: KALI LINUX 调试: EDB (KALI自带的) 一个简单的动态追码, 大牛们就略过吧…… 用16 ...

  8. unity中的[xxxxxx]特性(Attributes)

    [SerializeField] 在Inspector版面中显示非public属性,并且序列化:若写在public前面,等于没写. [Obsolete("调用提示信息")] [No ...

  9. ural 1180 Stone Game

    http://acm.timus.ru/problem.aspx?space=1&num=1180 #include <cstdio> #include <cstring&g ...

  10. Usage、Usage Minimum和Usage Maximum项目详解

    (1)一个产生多个数据域(Report Count>1)的主项目之前有一个以上的[用途]时,每个[用途]与一个数据域依次对应,如果数据域个数(Report Count)超过[用途]的个数,则剩余 ...