src/app/header/header.component.ts
The header component
selector | header |
styles | h1 {
margin-top: 75px;
} |
templateUrl | ./header.component.html |
Properties |
Methods |
Inputs |
constructor(todoStore: TodoStore)
|
||||||
Defined in src/app/header/header.component.ts:32
|
||||||
Parameters :
|
newTodoText | |
Type : string
|
|
Default value : ''
|
|
Defined in src/app/header/header.component.ts:32
|
|
The data-binding value of the input tag, added on enter to the todo store |
addTodo |
addTodo()
|
Defined in src/app/header/header.component.ts:41
|
Ad a todo to the list
Returns :
void
|
title |
Type : string
|
Default value : 'todos'
|
Defined in src/app/header/header.component.ts:21
|
Application main title |
todoStore |
Type : TodoStore
|
Defined in src/app/header/header.component.ts:26
|
Local reference of TodoStore |
import { Component, Input } from '@angular/core';
import { TodoStore } from '../shared/services/todo.store';
/**
* The header component
*/
@Component({
selector: 'header',
templateUrl: './header.component.html',
styles: [
`h1 {
margin-top: 75px;
}`
]
})
export class HeaderComponent {
/**
* Application main title
*/
title = 'todos';
/**
* Local reference of TodoStore
*/
todoStore: TodoStore;
/**
* The data-binding value of the input tag, added on enter to the todo store
*/
@Input()
newTodoText = '';
constructor(todoStore: TodoStore) {
this.todoStore = todoStore;
}
/**
* Ad a todo to the list
*/
addTodo() {
if (this.newTodoText.trim().length) {
this.todoStore.add(this.newTodoText);
this.newTodoText = '';
}
}
}
<h1>{{title}}</h1>
<input class="new-todo" placeholder="What needs to be done?" autofocus="" [(ngModel)]="newTodoText" (keyup.enter)="addTodo()">
h1 {
margin-top: 75px;
}