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 { FormsModule } from '@angular/forms';
import { AppComponent } from './app.cmp'; 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({ @NgModule({
imports: [ imports: [ BrowserModule, HttpModule, FormsModule],
BrowserModule, declarations: [ AppComponent ],
HttpModule, FormsModule, providers: [],
RouterModule.forRoot(routes, { useHash: true }) ],
declarations: [ AppComponent, ListComponent, ViewComponent ],
providers: [ TaskService ],
bootstrap: [ AppComponent ] bootstrap: [ AppComponent ]
}) })
export class AppModule { } export class AppModule { }

View File

@ -1,26 +1,21 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router' import { ActivatedRoute, Router } from '@angular/router'
import { Task, TaskService } from '../task.srv'; import { TaskService } from '../task.srv';
@Component({ @Component({
templateUrl: 'app/view/view.html' templateUrl: 'app/view/view.html'
}) })
export class ViewComponent implements OnInit { export class ViewComponent implements OnInit {
task: Task;
constructor(private route: ActivatedRoute, constructor(private route: ActivatedRoute,
private router: Router, private router: Router,
private taskService: TaskService) {} private taskService: TaskService) {}
back() { back() {
this.router.navigateByUrl('/list');
} }
ngOnInit(): void { 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> Title: {{ }}<br>
Added: {{ task?.added | date: 'dd-MM-yyyy hh:mm' }}<br><br> Added: {{ }}<br><br>
<button (click)="back()">Back</button> <button (click)="back()">Back</button>