Seeking assistance in updating an observable retrieved in html format from an API call.
If anyone has any insights on how to achieve this, your help would be greatly appreciated.
The corresponding html (in another component) is:
<common-content [theme]="theme" ></common-content>
and the respective component code is as follows:
import { Component, OnInit, Input } from '@angular/core';
import { Http, Response } from '@angular/http';
import { ThemeModel } from '../../models';
import 'rxjs/add/operator/toPromise';
@Component({
selector: 'common-content',
template: `<div innerHTML = "{{innerHtml}}"></div>`
})
export class CommonContentComponent implements OnInit {
@Input() page: string;
@Input() theme: ThemeModel;
innerHtml: string;
constructor(private http: Http) {
}
ngOnInit() {
this.populatePage();
}
populatePage(){
let thisUrl = 'myPage.html';
this.http.get(thisUrl).subscribe(f => {
var content = <string>f['_body'];
this.innerHtml = content.replace("{{theme.Name}}", this.theme.name);
}, (error) => {
let e = error;
}, () => {
});
}
}
The goal is for the observable to update automatically instead of using "replace". Attempts have been made with both subscribe and promises, but syntax issues persist.
If you have any suggestions or solutions, please share them. Your assistance is appreciated.
Thank you.