1- import {
2- Component ,
3- ChangeDetectorRef ,
4- ChangeDetectionStrategy
5- } from '@angular/core' ;
1+ import { Component } from '@angular/core' ;
62import { CORE_DIRECTIVES } from '@angular/common' ;
73import { Todo } from './todo.model' ;
84import { CompletedFilterPipe } from './completed-filter.pipe' ;
@@ -11,15 +7,14 @@ import {CompletedFilterPipe} from './completed-filter.pipe';
117 selector : 'as-todolist' ,
128 templateUrl : 'app/todolist/todolist.html' ,
139 directives : [ CORE_DIRECTIVES ] ,
14- pipes : [ CompletedFilterPipe ] ,
15- changeDetection : ChangeDetectionStrategy . OnPush
10+ pipes : [ CompletedFilterPipe ]
1611} )
1712export class TodolistComponent {
1813 public todo : Todo ;
1914 private list : Todo [ ] ;
2015 private showCompleted : Boolean ;
2116
22- constructor ( private _ref : ChangeDetectorRef ) {
17+ constructor ( ) {
2318 this . showCompleted = true ;
2419 this . todo = new Todo ( 'Add me to list!' , false ) ;
2520 this . list = [
@@ -31,14 +26,10 @@ export class TodolistComponent {
3126 addTodo ( ) {
3227 this . list = this . list . concat ( Todo . clone ( this . todo ) ) ;
3328 this . todo . clear ( ) ;
34- this . _ref . markForCheck ( ) ;
3529 }
3630
37- delTodo ( index : number ) {
38- this . list = [ ] . concat (
39- this . list . slice ( 0 , index ) ,
40- this . list . slice ( index + 1 , this . list . length )
41- ) ;
42- this . _ref . markForCheck ( ) ;
31+ delTodo ( todoIndex : number ) {
32+ this . list = this . list . filter (
33+ ( todo , index ) => index !== todoIndex ) ;
4334 }
4435}
0 commit comments