[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的更多相关文章
- [Javascript] Keyword 'in' to check prop exists on Object
function addTo80(n ) { + n; } function memoizedAddTo80 (fn) { let cache = {}; return (n) => { /*k ...
- 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 & ...
- Error:Uninitialized object exists on backward branch 70 Exception Details:
网上下载了一个demo,编译出现如下错误: Gradle sync failed: Uninitialized object exists on backward branch 70 Exceptio ...
- Angular源代码学习笔记-原创
时间:2014年12月15日 14:15:10 /** * @license AngularJS v1.3.0-beta.15 * (c) 2010-2014 Google, Inc. http:// ...
- angular源码分析:angular中各种常用函数,比较省代码的各种小技巧
angular的工具函数 在angular的API文档中,在最前面就是讲的就是angular的工具函数,下面列出来 angular.bind //用户将函数和对象绑定在一起,返回一个新的函数 angu ...
- [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 ...
- 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 ...
- Angular CLI 升级 6.0 之后遇到的问题
Angular CLI 1.7.4 在使用 ng build --prod 会构建失败,而 ng build 是正常的.比较好的解决办法是使用 ng build --prod --extract-li ...
- Unity Shaderlab: Object Outlines 转
转 https://willweissman.wordpress.com/tutorials/shaders/unity-shaderlab-object-outlines/ Unity Shader ...
随机推荐
- C#中如何获取系统环境变量等
C#中获取系统环境变量需要用到Environment 类. 其中提供了有关当前环境和平台的信息以及操作它们的方法.该类不能被继承 以下代码得到%systemdrive%的值,即“C:” string ...
- telnet与tnsping
在cmd 下面 tnsping ZCGL ZCGL这个是在oracle做好的数据库连接. telnet IP地址 加上端口号. 查看视图的编写语句 select dbms_metadata.get_d ...
- PHP MySQLi
PHP MySQLi 简介 PHP MySQLi = PHP MySQL Improved! MySQLi 函数允许您访问 MySQL 数据库服务器. 注释:MySQLi 扩展被设计用于 MySQL ...
- Python正则表达式一
推荐 http://www.cnblogs.com/huxi/archive/2010/07/04/1771073.html#!comments 这篇博客超好,建议收藏. 不过对于正则表达式小白,他没 ...
- python记录
1. 序列的分片操作:需要提供两个索引作为边界,第1个索引的元素包含在分片内,第2个索引的元素不包含在分片内. 为了能让分片部分能够包含列表的最后一个元素,必需提供最后一个元素的下一个元素所对应的索引 ...
- Css3 javascript 写的分类
不兼容IE10以下的浏览器 <!DOCTYPE html> <html> <head> <meta charset=utf-> <title> ...
- [kuangbin带你飞]专题十 匹配问题 二分图最大权匹配
二分图最大权匹配有km算法和网络流算法 km算法模板默认解决最大权匹配的问题 而使用最小费用最大流 是解决最小权匹配问题 这两种办法都可以求最大最小权 需要两次取反 TAT 感觉讲km会很难的样子.. ...
- Orchard之创建模板
orchard创建模板的两种基本方式: 第一种:通过候补创建(需要用到候补神器): 第二种:通过Shape Tracing创建:
- 从汇编来看c语言之变量
1.基础研究 对如图程序进行编译连接,再用debug加载. 我们在偏移地址1fa处查看main函数的内容: 执行到1fd处,发现n的偏移地址为01a6,段地址存储在ds寄存器里,为07c4. 再查看函 ...
- Cracking the coding interview--Q1.8
原文: Assume you have a method isSubstring which checks if one word is a substring of another. Given t ...