I am creating a custom component which loads the innerHTML from a remote source. My question is how can i load the content when app loads. Right now, the content loads when the page shows and its a small delay until the text appears. Is there an event i can attach to that component to load the content when the app loads?
This is how my component looks like:
import {Component} from 'angular2/core'
import {DataProvider} from '../../providers/DataProvider'
@Component({
'selector': 'ck-tos',
templateUrl: 'build/directives/ckTos/ckTos.html',
providers: [[Cashklick]],
})
export class ckTos {
content: String = "";
constructor(private DataProvider: DataProvider) {
DataProvider.load('pages', 'terms').subscribe(
data => {
let response = data.json();
if (response.content)
this.content = response.content;
else if (response.error)
this.content = response.error;
else
this.content = "Error: Unable to get any data ...";
},
err => {this.content = "Error: Unable to get any data ...";},
() => console.log('DataProvider service for page terms completed')
);
}
}
When i open the app, i want this component to have content variable loaded and used without calling the remote service each time the component is rendered.