This repository was archived by the owner on Jun 22, 2022. It is now read-only.
forked from PatrickJS/PatrickJS-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabout.component.ts
65 lines (57 loc) · 1.74 KB
/
about.component.ts
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
/*
* We're loading this component asynchronously
* We are using some magic with es6-promise-loader that will wrap the module with a Promise
* see https://github.com/gdi2290/es6-promise-loader for more info
*/
console.info('`About` component loaded asynchronously');
@Component({
selector: 'my-about',
styles: [`
`],
template: `
<h1>About</h1>
<div>
For hot module reloading run
<pre>npm run start:hmr</pre>
</div>
<div>
<h3>
</h3>
</div>
<pre>this.localState = {{ localState | json }}</pre>
`,
})
export class AboutComponent implements OnInit {
public localState: any;
constructor(public route: ActivatedRoute) {
}
public ngOnInit(): void {
this.route
.data
.subscribe((data: any) => {
// your resolved data from route
this.localState = data.yourData;
});
console.info('hello `About` component');
// static data that is bundled
// var mockData = require('assets/mock-data/mock-data.json');
// console.debug('mockData', mockData);
// if you're working with mock data you can also use http.get('assets/mock-data/mock-data.json')
this.asyncDataWithWebpack();
}
private asyncDataWithWebpack(): void {
// you can also async load mock data with 'es6-promise-loader'
// you would do this if you don't want the mock-data bundled
// remember that 'es6-promise-loader' is a promise
setTimeout(() => {
System.import('../../assets/mock-data/mock-data.json')
.then(json => {
console.info('async mockData', json);
this.localState = json;
});
});
}
}