Skip to content

Commit 408574f

Browse files
author
Suraj Chandgude
committed
Added add-note & navigation with routing
1 parent 8a3c4bb commit 408574f

17 files changed

+231
-40
lines changed

src/app/app-routing.module.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
import { NgModule } from '@angular/core';
22
import { Routes, RouterModule } from '@angular/router';
3+
import { TodosComponent } from './components/todos/todos.component';
34

4-
const routes: Routes = [];
5+
const routes: Routes = [
6+
{
7+
path: '',
8+
component: TodosComponent
9+
},
10+
// {
11+
// path: '',
12+
// component:
13+
// }
14+
];
515

616
@NgModule({
717
imports: [RouterModule.forRoot(routes)],

src/app/app.component.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
<app-todos></app-todos>
1+
<div>
2+
<app-header></app-header>
3+
<router-outlet></router-outlet>
4+
</div>

src/app/app.module.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
1+
import { HttpClient, HttpClientModule } from "@angular/common/http";
12
import { BrowserModule } from '@angular/platform-browser';
23
import { NgModule } from '@angular/core';
4+
import { FormsModule } from '@angular/forms';
35

46
import { AppRoutingModule } from './app-routing.module';
57
import { AppComponent } from './app.component';
68
import { TodosComponent } from './components/todos/todos.component';
79
import { TodoItemComponent } from './components/todo-item/todo-item.component';
8-
10+
import { HeaderComponent } from './components/layout/header/header.component';
11+
import { AddTodoComponent } from './components/add-todo/add-todo.component';
912
@NgModule({
1013
declarations: [
1114
AppComponent,
1215
TodosComponent,
13-
TodoItemComponent
16+
TodoItemComponent,
17+
HeaderComponent,
18+
AddTodoComponent
1419
],
1520
imports: [
1621
BrowserModule,
17-
AppRoutingModule
22+
AppRoutingModule,
23+
HttpClientModule,
24+
FormsModule
25+
1826
],
1927
providers: [],
2028
bootstrap: [AppComponent]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<form class="form">
2+
<input type="text" [(ngModel)]="title" name="title" placeholder="Add todo...">
3+
<input type="button" value="submit" class="btn" (click)="onSubmit()">
4+
</form>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.form {
2+
display: flex;
3+
}
4+
5+
.form input[type='text'] {
6+
flex: 10;
7+
padding: 5px;
8+
}
9+
10+
.form input[type='submit'] {
11+
flex: 2;
12+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { AddTodoComponent } from './add-todo.component';
4+
5+
describe('AddTodoComponent', () => {
6+
let component: AddTodoComponent;
7+
let fixture: ComponentFixture<AddTodoComponent>;
8+
9+
beforeEach(async(() => {
10+
TestBed.configureTestingModule({
11+
declarations: [ AddTodoComponent ]
12+
})
13+
.compileComponents();
14+
}));
15+
16+
beforeEach(() => {
17+
fixture = TestBed.createComponent(AddTodoComponent);
18+
component = fixture.componentInstance;
19+
fixture.detectChanges();
20+
});
21+
22+
it('should create', () => {
23+
expect(component).toBeTruthy();
24+
});
25+
});
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { Component, OnInit, Output, EventEmitter } from '@angular/core';
2+
3+
@Component({
4+
selector: 'app-add-todo',
5+
templateUrl: './add-todo.component.html',
6+
styleUrls: ['./add-todo.component.scss']
7+
})
8+
export class AddTodoComponent implements OnInit {
9+
10+
@Output() addTodo: EventEmitter<any> = new EventEmitter;
11+
12+
title: string;
13+
14+
constructor() { }
15+
16+
ngOnInit() {
17+
}
18+
19+
onSubmit() {
20+
console.log("Hi")
21+
let todo = {
22+
title: this.title,
23+
completed: false
24+
}
25+
this.addTodo.emit(todo);
26+
console.log("TCL: AddTodoComponent -> onSubmit -> todo", todo)
27+
}
28+
29+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<header class="header">
2+
<h1>TodoList</h1>
3+
<nav>
4+
<a routerLink="/">Home</a>
5+
</nav>
6+
</header>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
.header {
3+
background: #333;
4+
color: #fff;
5+
text-align: center;
6+
padding: 10px;
7+
}
8+
9+
.header a {
10+
color: #fff;
11+
text-decoration: none;
12+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { HeaderComponent } from './header.component';
4+
5+
describe('HeaderComponent', () => {
6+
let component: HeaderComponent;
7+
let fixture: ComponentFixture<HeaderComponent>;
8+
9+
beforeEach(async(() => {
10+
TestBed.configureTestingModule({
11+
declarations: [ HeaderComponent ]
12+
})
13+
.compileComponents();
14+
}));
15+
16+
beforeEach(() => {
17+
fixture = TestBed.createComponent(HeaderComponent);
18+
component = fixture.componentInstance;
19+
fixture.detectChanges();
20+
});
21+
22+
it('should create', () => {
23+
expect(component).toBeTruthy();
24+
});
25+
});

0 commit comments

Comments
 (0)