File

src/app/footer/footer.component.ts

Description

The footer component

Metadata

Index

Properties
Methods

Constructor

constructor(todoStore: TodoStore)

The "constructor"

Parameters :
Name Type Optional Description
todoStore TodoStore No

A TodoStore

Methods

displayAll
displayAll()

Display all todos

Returns : void
displayCompleted
displayCompleted()

Display only completed todos

Returns : void
displayRemaining
displayRemaining()

Display only remaining todos

Returns : void
removeCompleted
removeCompleted()
Decorators :
@LogMethod()

Removes all the completed todos

Returns : void

Properties

currentFilter
Type : string
Default value : 'all'
Decorators :
@LogPropertyWithArgs('theCurrentFilter')

Starting filter param

id
Type : string
Default value : 'FooterComponent'
Decorators :
@LogProperty()

Local id for EmitterService

todoStore
Type : TodoStore

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>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""