angular/angular.io/src/app/nav-engine/nav-engine.service.ts
2017-02-02 23:28:00 -08:00

35 lines
930 B
TypeScript

declare var fetch;
import { Injectable } from '@angular/core';
// TODO(robwormald): figure out how to handle this properly...
const siteMap = [
{ 'title': 'Home', 'url': 'assets/documents/home.html', id: 'home'},
{ 'title': 'Features', 'url': 'assets/documents/features.html', id: 'features'},
{ 'title': 'News', 'url': 'assets/documents/news.html', id: 'news'}
];
@Injectable()
export class NavEngine {
currentDoc: any;
constructor() {}
navigate(documentId) {
console.log('navigating to', documentId);
const doc = siteMap.find(d => d.id === documentId);
if (doc) {
this.fetchDoc(doc.url)
.then(content => {
console.log('fetched content', content);
this.currentDoc = Object.assign({}, doc, {content});
});
}
}
private fetchDoc(url) {
// TODO(robwormald): use Http proper once new API is done.
return fetch(url).then(res => res.text());
}
}