-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresolve.js
34 lines (23 loc) · 881 Bytes
/
resolve.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { Component, OnInit } from '@angular/core';
import {SeuService} from './seuService';
import {Router,
ActivatedRoute, Resolve,
ActivatedRouteSnapshot} from '@angular/router';
import {Observable} from 'rxjs/Rx';
@Component({
templateUrl: "./home.component.html"
})
export class HomeComponent implements OnInit, Resolve<any> {
constructor(private seuService:SeuService, private route: ActivatedRoute) { }
//este método será executando antes do componente ser renderizado
resolve(route: ActivatedRouteSnapshot): Observable<any> {
return this.seuService.getSeusDados();
}
//o método ngOnInit receberá o retorno do médoto resolve
ngOnInit(){
if(this.route.snapshot.data['dados'])
{
console.log(this.route.snapshot.data['dados']);
}
}
}