starting state

This commit is contained in:
Märt Kalmo 2017-04-29 11:38:09 +03:00
parent cec00f891c
commit 56533dfb39
4 changed files with 7 additions and 20 deletions

View File

@ -1 +1 @@
<router-outlet></router-outlet>
Hello Angular 2+

View File

@ -4,19 +4,11 @@ import { HttpModule } from '@angular/http';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.cmp';
import { RouterModule } from "@angular/router";
import { routes } from "./routes";
import { ListComponent } from "./list/list.cmp";
import { ViewComponent } from "./view/view.cmp";
import { TaskService } from "./task.srv";
@NgModule({
imports: [
BrowserModule,
HttpModule, FormsModule,
RouterModule.forRoot(routes, { useHash: true }) ],
declarations: [ AppComponent, ListComponent, ViewComponent ],
providers: [ TaskService ],
imports: [ BrowserModule, HttpModule, FormsModule],
declarations: [ AppComponent ],
providers: [],
bootstrap: [ AppComponent ]
})
export class AppModule { }

View File

@ -1,26 +1,21 @@
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router'
import { Task, TaskService } from '../task.srv';
import { TaskService } from '../task.srv';
@Component({
templateUrl: 'app/view/view.html'
})
export class ViewComponent implements OnInit {
task: Task;
constructor(private route: ActivatedRoute,
private router: Router,
private taskService: TaskService) {}
back() {
this.router.navigateByUrl('/list');
}
ngOnInit(): void {
const id = parseInt(this.route.snapshot.paramMap.get('id'));
this.taskService.getTask(id).then(task => this.task = task);
}
}

View File

@ -1,5 +1,5 @@
Title: {{ task?.title }}<br>
Added: {{ task?.added | date: 'dd-MM-yyyy hh:mm' }}<br><br>
Title: {{ }}<br>
Added: {{ }}<br><br>
<button (click)="back()">Back</button>