UNPKG

malgo-brat-frontend-editor

Version:
66 lines (57 loc) 1.7 kB
import { Component } 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.log('`About` component loaded asynchronously'); @Component({ selector: 'about', styles: [` `], template: ` <h1>About</h1> <div> For hot module reloading run <pre>npm run start:hmr</pre> </div> <div> <h3> patrick@AngularClass.com </h3> </div> <pre>this.localState = {{ localState | json }}</pre> ` }) export class About { localState: any; constructor(public route: ActivatedRoute) { } ngOnInit() { this.route .data .subscribe((data: any) => { // your resolved data from route this.localState = data.yourData; }); console.log('hello `About` component'); // static data that is bundled // var mockData = require('assets/mock-data/mock-data.json'); // console.log('mockData', mockData); // if you're working with mock data you can also use http.get('assets/mock-data/mock-data.json') this.asyncDataWithWebpack(); } asyncDataWithWebpack() { // 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.log('async mockData', json); this.localState = json; }); }); } }