我无法填充来自Observable的ng2-ace-editor文本(from
和delay
应该模仿未来的服务。)
page.component.html:
<ace-editor #editor
style="height:350px;"
[text]="code"
[mode]="'html'"
[theme]="'clouds'"
[readOnly]="false"
[autoUpdateContent]="true"
></ace-editor>
page.component.ts:
export class PageComponent implements AfterViewInit, OnInit {
code: string = '';
editorOptions: any = {
showPrintMargin: false,
showInvisibles: true,
highlightGutterLine: true,
};
@ViewChild('editor') editor;
ngOnInit() {
this._dummyGetUserHtml().subscribe(data => {
this.code = data; // why won't this work?
this.editor.getEditor().setValue(data); // and we need this?
console.log('code', data);
});
}
ngAfterViewInit() {
this.editor.getEditor().setOptions(this.editorOptions);
}
private _dummyGetUserHtml(){
return Observable.from([
`<body><p>Hello world!</p></body>`
]).delay(1000);
}
}
我做错了什么? (当我将订阅移至ngAfterViewInit
)
我的意思是:我知道而不是:this.code = data
我可以this.editor.getEditor().setValue(data)
,但由于包说明组件接受text
为@Input
,我希望我的原始代码应该可以在不使用api方法的情况下工作。