src/app/footer/footer.component.ts
The footer component
selector | footer |
templateUrl | ./footer.component.html |
Properties |
Methods |
constructor(todoStore: TodoStore)
|
||||||||
Defined in src/app/footer/footer.component.ts:32
|
||||||||
The "constructor"
Parameters :
|
displayAll |
displayAll()
|
Defined in src/app/footer/footer.component.ts:81
|
Display all todos
Returns :
void
|
displayCompleted |
displayCompleted()
|
Defined in src/app/footer/footer.component.ts:65
|
Display only completed todos
Returns :
void
|
displayRemaining |
displayRemaining()
|
Defined in src/app/footer/footer.component.ts:73
|
Display only remaining todos
Returns :
void
|
removeCompleted |
removeCompleted()
|
Decorators :
@LogMethod()
|
Defined in src/app/footer/footer.component.ts:47
|
Removes all the completed todos
Returns :
void
|
currentFilter |
Type : string
|
Default value : 'all'
|
Decorators :
@LogPropertyWithArgs('theCurrentFilter')
|
Defined in src/app/footer/footer.component.ts:32
|
Starting filter param |
id |
Type : string
|
Default value : 'FooterComponent'
|
Decorators :
@LogProperty()
|
Defined in src/app/footer/footer.component.ts:27
|
Local id for EmitterService |
todoStore |
Type : TodoStore
|
Defined in src/app/footer/footer.component.ts:22
|
Local reference of TodoStore |
import { Component } from '@angular/core';
import { TodoStore } from '../shared/services/todo.store';
import { EmitterService } from '../shared/services/emitter.service';
import { LogMethod, LogProperty, LogPropertyWithArgs, LogClass } from '../shared/decorators/log.decorator';
/**
* The footer component
*/
@LogClass
@Component({
selector: 'footer',
providers: [],
templateUrl: './footer.component.html'
})
export class FooterComponent {
/**
* Local reference of TodoStore
*/
todoStore: TodoStore;
/**
* Local id for EmitterService
*/
@LogProperty
id = 'FooterComponent';
/**
* Starting filter param
*/
@LogPropertyWithArgs('theCurrentFilter')
currentFilter = 'all';
/**
* The "constructor"
*
* @param {TodoStore} todoStore A TodoStore
*/
constructor(todoStore: TodoStore) {
this.todoStore = todoStore;
}
/**
* Removes all the completed todos
*/
@LogMethod
removeCompleted() {
this.todoStore.removeCompleted();
switch (this.currentFilter) {
case 'completed':
EmitterService.get(this.id).emit('displayCompleted');
break;
case 'remaining':
EmitterService.get(this.id).emit('displayRemaining');
break;
case 'all':
EmitterService.get(this.id).emit('displayAll');
break;
}
}
/**
* Display only completed todos
*/
displayCompleted() {
this.currentFilter = 'completed';
EmitterService.get(this.id).emit('displayCompleted');
}
/**
* Display only remaining todos
*/
displayRemaining() {
this.currentFilter = 'remaining';
EmitterService.get(this.id).emit('displayRemaining');
}
/**
* Display all todos
*/
displayAll() {
this.currentFilter = 'all';
EmitterService.get(this.id).emit('displayAll');
}
}
<div class="footer" *ngIf="todoStore.todos.length > 0">
<span class="todo-count"><strong>{{todoStore.getRemaining().length}}</strong> {{todoStore.getRemaining().length == 1 ? 'item' : 'items'}} left</span>
<ul class="filters">
<li>
<a class="selected btn-filter" [class.selected]="currentFilter === 'all'" (click)="displayAll()">All</a>
</li>
<li>
<a class="btn-filter" [class.selected]="currentFilter === 'remaining'" (click)="displayRemaining()">Active</a>
</li>
<li>
<a class="btn-filter" [class.selected]="currentFilter === 'completed'" (click)="displayCompleted()">Completed</a>
</li>
</ul>
<button class="clear-completed" *ngIf="todoStore.getCompleted().length > 0" (click)="removeCompleted()">Clear completed</button>
</div>