-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
269 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,11 @@ | ||
<section class="todoapp"> | ||
<header class="header"> | ||
<h1>Todos</h1> | ||
<input class="new-todo" placeholder="what needs to be done ?" autofocus="" [(ngModel)]="newTodo.title" (keyup.enter)="addTodo()"> | ||
</header> | ||
<section class="main" *ngIf="todos.length > 0"> | ||
<ul> | ||
<li *ngFor="let todo of todos" [class.complete]="todo.complete"> | ||
<div class="view"> | ||
<input class="toggle" type="checkbox" (click)="toggleTodoComplete(todo)" [checked]="todo.complete"> | ||
<label>{{ todo.title }}</label> | ||
<button class="destroy" (click)="removeTodo(todo)"></button> | ||
</div> | ||
</li> | ||
</ul> | ||
</section> | ||
<footer class="footer" *ngIf="todos.length > 0"> | ||
<span class="todo-count"><strong>{{ todos.length }}</strong> {{ todos.length == 1 ? "item" : "items"}} left</span> | ||
</footer> | ||
<app-todo-list-header (add)="onAddTodo($event)"></app-todo-list-header> | ||
<app-todo-list | ||
[todos]="todos" | ||
(toggleComplete)="onToggleTodoComplete($event)" | ||
(remove)="onRemoveTodo($event)" | ||
></app-todo-list> | ||
<app-todo-list-footer | ||
[todos]="todos" | ||
></app-todo-list-footer> | ||
</section> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,26 @@ | ||
import { TodoDataService } from './TodoData.service'; | ||
import { FormsModule } from '@angular/forms'; | ||
import { NgModule } from '@angular/core'; | ||
import { BrowserModule } from '@angular/platform-browser'; | ||
|
||
import { AppComponent } from './app.component'; | ||
import { TodoListHeaderComponent } from './todo-list-header/todo-list-header.component'; | ||
import { TodoListComponent } from './todo-list/todo-list.component'; | ||
import { TodoListItemComponent } from './todo-list-item/todo-list-item.component'; | ||
import { TodoListFooterComponent } from './todo-list-footer/todo-list-footer.component'; | ||
|
||
@NgModule({ | ||
declarations: [ | ||
AppComponent | ||
], | ||
AppComponent, | ||
TodoListHeaderComponent, | ||
TodoListComponent, | ||
TodoListItemComponent, | ||
TodoListFooterComponent | ||
], | ||
imports: [ | ||
BrowserModule | ||
BrowserModule,FormsModule | ||
], | ||
providers: [], | ||
providers: [TodoDataService], | ||
bootstrap: [AppComponent] | ||
}) | ||
export class AppModule { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<footer class="footer" *ngIf="todos.length > 0"> | ||
<span class="todo-count"><strong>{{ todos.length }}</strong> {{ todos.length == 1 ? "item" : "items"}} left</span> | ||
</footer> |
28 changes: 28 additions & 0 deletions
28
src/app/todo-list-footer/todo-list-footer.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* tslint:disable:no-unused-variable */ | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { By } from '@angular/platform-browser'; | ||
import { DebugElement } from '@angular/core'; | ||
|
||
import { TodoListFooterComponent } from './todo-list-footer.component'; | ||
|
||
describe('TodoListFooterComponent', () => { | ||
let component: TodoListFooterComponent; | ||
let fixture: ComponentFixture<TodoListFooterComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ TodoListFooterComponent ] | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(TodoListFooterComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Todo } from './../todo'; | ||
import { Component, Input, OnInit } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'app-todo-list-footer', | ||
templateUrl: './todo-list-footer.component.html', | ||
}) | ||
export class TodoListFooterComponent implements OnInit { | ||
|
||
@Input() todos: Todo[]; | ||
|
||
constructor() { } | ||
|
||
ngOnInit() { | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<header class="header"> | ||
<h1>Todos</h1> | ||
<input class="new-todo" placeholder="what needs to be done ?" autofocus="" [(ngModel)]="newTodo.title" (keyup.enter)="addTodo()"> | ||
</header> |
28 changes: 28 additions & 0 deletions
28
src/app/todo-list-header/todo-list-header.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* tslint:disable:no-unused-variable */ | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { By } from '@angular/platform-browser'; | ||
import { DebugElement } from '@angular/core'; | ||
|
||
import { TodoListHeaderComponent } from './todo-list-header.component'; | ||
|
||
describe('TodoListHeaderComponent', () => { | ||
let component: TodoListHeaderComponent; | ||
let fixture: ComponentFixture<TodoListHeaderComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ TodoListHeaderComponent ] | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(TodoListHeaderComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Component, EventEmitter, OnInit, Output } from '@angular/core'; | ||
import { Todo } from '../todo'; | ||
|
||
@Component({ | ||
selector: 'app-todo-list-header', | ||
templateUrl: './todo-list-header.component.html', | ||
}) | ||
export class TodoListHeaderComponent implements OnInit { | ||
newTodo: Todo = new Todo(); | ||
|
||
@Output() add:EventEmitter<Todo> = new EventEmitter(); | ||
|
||
constructor() { } | ||
|
||
ngOnInit() { | ||
} | ||
|
||
addTodo(){ | ||
this.add.emit(this.newTodo); | ||
this.newTodo = new Todo(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<div class="view"> | ||
<input class="toggle" type="checkbox" (click)="toggleTodoComplete(todo)" [checked]="todo.complete"> | ||
<label>{{ todo.title }}</label> | ||
<button class="destroy" (click)="removeTodo(todo)"></button> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* tslint:disable:no-unused-variable */ | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { By } from '@angular/platform-browser'; | ||
import { DebugElement } from '@angular/core'; | ||
|
||
import { TodoListItemComponent } from './todo-list-item.component'; | ||
|
||
describe('TodoListItemComponent', () => { | ||
let component: TodoListItemComponent; | ||
let fixture: ComponentFixture<TodoListItemComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ TodoListItemComponent ] | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(TodoListItemComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Todo } from './../todo'; | ||
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'app-todo-list-item', | ||
templateUrl: './todo-list-item.component.html', | ||
}) | ||
export class TodoListItemComponent implements OnInit { | ||
|
||
@Input() todo: Todo; | ||
|
||
@Output() remove: EventEmitter<Todo> = new EventEmitter(); | ||
|
||
@Output() toggleComplete: EventEmitter<Todo> = new EventEmitter(); | ||
|
||
constructor() { } | ||
|
||
ngOnInit() { | ||
} | ||
|
||
removeTodo(todo: Todo){ | ||
this.remove.emit(todo); | ||
} | ||
|
||
toggleTodoComplete(todo: Todo){ | ||
this.toggleComplete.emit(todo); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<section class="main" *ngIf="todos.length > 0"> | ||
<ul> | ||
<li *ngFor="let todo of todos" [class.complete]="todo.complete"> | ||
<app-todo-list-item | ||
[todo]="todo" | ||
(toggleComplete)="onToggleTodoComplete($event)" | ||
(remove)="onRemoveTodo($event)" | ||
> | ||
</app-todo-list-item> | ||
</li> | ||
</ul> | ||
</section> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* tslint:disable:no-unused-variable */ | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { By } from '@angular/platform-browser'; | ||
import { DebugElement } from '@angular/core'; | ||
|
||
import { TodoListComponent } from './todo-list.component'; | ||
|
||
describe('TodoListComponent', () => { | ||
let component: TodoListComponent; | ||
let fixture: ComponentFixture<TodoListComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ TodoListComponent ] | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(TodoListComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Todo } from './../todo'; | ||
import { Component, Input, OnInit, Output, EventEmitter } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'app-todo-list', | ||
templateUrl: './todo-list.component.html', | ||
}) | ||
export class TodoListComponent implements OnInit { | ||
|
||
@Input() todos: Todo[]; | ||
|
||
@Output() remove: EventEmitter<Todo> = new EventEmitter(); | ||
|
||
@Output() toggleComplete: EventEmitter<Todo> = new EventEmitter(); | ||
|
||
constructor() { } | ||
|
||
ngOnInit() { | ||
} | ||
|
||
onToggleComplete(todo: Todo){ | ||
this.toggleComplete.emit(todo); | ||
} | ||
|
||
onRemoveTodo(todo: Todo){ | ||
this.remove.emit(todo); | ||
} | ||
|
||
} |