Pipes need a new reference or else they will not update their output. In this lesson you will use the Array ...spread operator to create new Array to update pipe output without mutation.

Currently on our TodoInput.ts, each time you add a new todo into the list, we can see that the TodoModule get updated, but it not showing in the list, this is because Pipes check the reference, it object reference changes then it will update the Pipe. This is good because it can imrpove the prefermence by saving everytime check whether need to update the pipes.

To make pipe update itself, we need everytime pass in a new reference. So immutable state is required, for example we need to change the current code:

    onSubmit() {
this.todoService.todos.push(this.todoModule);
// After insert, create new TodoModule
this.todoModule = new TodoModule();
console.log(this.todoService.todos);
}

To immutable state:

    onSubmit() {
this.todoService.addNewTodo(this.todoModule);
// After insert, create new TodoModule
this.todoModule = new TodoModule();
console.log(this.todoService.todos);
} //TodoService.ts:
addNewTodo(todo){
this.todos = [...this.todos, todo];
}

-----------------------------------

[Angular 2] Using Array ...spread to enforce Pipe immutability的更多相关文章

  1. [Angular 2] Controlling Rx Subscriptions with Async Pipe and BehaviorSubjects

    Each time you use the Async Pipe, you create a new subscription to the stream in the template. This ...

  2. [Angular 2] Rendering an Observable with the Async Pipe

    Angular 2 templates use a special Async pipe to be able to render out Observables. This lesson cover ...

  3. [Angular Unit Testing] Shallow Pipe Testing

    import { TestBed, ComponentFixture } from '@angular/core/testing'; import { BrowserDynamicTestingMod ...

  4. Angular 利用 marked.js 添加 Markdown + HTML 同时渲染的 Pipe

    背景 最近在公司开发的一个项目需要在 Angular 上展示图文,并且需要同时支持 Markdown 和 HTML 对于同时支持 Markdown 和 HTML ,应该要分为编辑和渲染两部分考虑. 对 ...

  5. Angular概念纵览

    Conceptual Overview Template(模板): HTML with additional markup (就是增加了新的标记的HTML) Directive(指令): extend ...

  6. Angular表单控件需要类型和实际值类型不一致时实现双向绑定

    适用Angular版本为:>=2.本文同样适用于Ionic这类的基于Angular实现的框架. 本文的思路也适用于控件显示的值和实际的值不一样时实现双向绑定. 1. 问题描述 在使用md2的da ...

  7. Angular 个人深究(一)【Angular中的Typescript 装饰器】

    Angular 个人深究[Angular中的Typescript 装饰器] 最近进入一个新的前端项目,为了能够更好地了解Angular框架,想到要研究底层代码. 注:本人前端小白一枚,文章旨在记录自己 ...

  8. Angular 1 深度解析:脏数据检查与 angular 性能优化

    TL;DR 脏检查是一种模型到视图的数据映射机制,由 $apply 或 $digest 触发. 脏检查的范围是整个页面,不受区域或组件划分影响 使用尽量简单的绑定表达式提升脏检查执行速度 尽量减少页面 ...

  9. AngularJS的核心对象angular上的方法全面解析(AngularJS全局API)

    总结一下AngularJS的核心对象angular上的方法,也帮助自己学习一下平时工作中没怎么用到的方法,看能不能提高开发效率.我当前使用的Angularjs版本是1.5.5也是目前最新的稳定版本,不 ...

随机推荐

  1. 单电机板机模型,f22

    视频连接 http://v.youku.com/v_show/id_XMTI5MDEzMzIxMg==.html?from=y1.7-1.2 http://v.youku.com/v_show/id_ ...

  2. PHP MYSQL读取中文乱码的解决办法

    其他试了很多种办法,结果最直接最简单的办法就是在SELECT前先发送设置.如下 mysqli_query($con,"SET NAMES 'UTF8'"); mysqli_quer ...

  3. mysql 查询copy to tmp table造成堵塞

    show full PROCESSLIST; show VARIABLES like 'tmp_table_size' set GLOBAL tmp_table_size=629145600; SHO ...

  4. HttpClient支持使用代理服务器以及身份认证

    HttpClient Authentication Doument: http://hc.apache.org/httpclient-3.x/authentication.html HttpClien ...

  5. IE6/IE7不识别display:inline-block属性怎么办

    ie6,ie7的haslayout属性是个让人头疼的问题.在做导航条的时候,一般会用到ul li结构,大多数时候我们是把li设置为浮动,让其并排显示在同一行.还有一种方法就是设置li为display: ...

  6. 使用Reaver加PIN码秒破WPA-PSK密码

    之前掌握到的破解WPA-PSK密码仅限于使用aircreack工具包获取handshake后挂字典爆破方式,而能否破解出wpa密码完全依赖于字典强度了.除了该方式外还有一个更有效的办法,就是使用路由P ...

  7. mongodb 增加用户以及认证用户

    test>use admin switched to db admin admin>db.addUser('yshy','yshy') { "user" : " ...

  8. CA

    http://www.cmca.net/index.php?option=com_content&view=article&id=55&Itemid=16

  9. Android中开发Service

    Service的开发分为两个步骤:定义Service和配置Service1.定义Service定义一个Service子类继承于Service2.配置Service在AndroidManifest.xm ...

  10. Android中的手势

    Android对两种手势行为提供了支持:1.对于第一种手势行为而言,Android提供了手势检测,并为手势检测提供了相应的监听器.2.对于第二种手势行为,Android允许开发者添加手势,并提供了相应 ...