Angular Template expression operators介绍

简介: Angular Template expression operators介绍

Angular template expression language是对JavaScript语法的增强和补充。


pipe operator

用法和操作系统里讲到的管道类似。


例子:


Title through uppercase pipe: {undefined{title | uppercase}}


pipe工作时也允许传入参数:


Manufacture date with date format pipe: {undefined{item.manufactureDate | date:'longDate'}}


json pipe对调试很有用:


Item json pipe: {undefined{item | json}}


safe navigation operator

下面的html代码,如果属性nullItem为null,

The null item name is {undefined{nullItem.name}}


Angular在渲染时会抛出异常:


TypeError: Cannot read property ‘name’ of null.


解决方案:


The null item name is {undefined{nullItem?.name}}


这样当Angular检测到nullItem为null时,会停止对表达式的evaluation,这样不会导致view的渲染出错。


@any function

<p>The item's undeclared best by date is: {{$any(item).bestByDate}}</p>

上面的$any可以避免Angular编译器报错:bestByDate is not a member of the item object

相关文章
Angular Component template函数执行上下文的对象
Angular Component template函数执行上下文的对象
Angular Component template函数执行上下文的对象
|
JavaScript
Angular内部对template的处理学习笔记
Angular内部对template的处理学习笔记
|
JavaScript
Angular refreshView里Component template函数的执行原理
Angular refreshView里Component template函数的执行原理
110 0
Angular refreshView里Component template函数的执行原理
|
JavaScript
Angular应用里的Template Reference变量
Angular应用里的Template Reference变量
117 0
|
存储 Web App开发 前端开发
ES6, Angular,React和ABAP中的String Template(字符串模板)
ES6, Angular,React和ABAP中的String Template(字符串模板)
171 0
ES6, Angular,React和ABAP中的String Template(字符串模板)
|
2月前
|
设计模式 JavaScript 前端开发
什么是 Angular 应用里的 Custom provider
什么是 Angular 应用里的 Custom provider
30 2
|
3月前
Angular 应用里异步打开对话框的技术实现
Angular 应用里异步打开对话框的技术实现
22 0
|
18天前
|
存储 JavaScript 前端开发
Angular 应用 node_modules 子文件夹 @types 的作用介绍
Angular 应用 node_modules 子文件夹 @types 的作用介绍
12 1

热门文章

最新文章