在Angular中实现文档视图的方式有很多种,下面给出其中一种方式:
import { Component } from '@angular/core';
@Component({
selector: 'app-document-view',
template: `
`,
})
export class DocumentViewComponent {
documentHtml: string = '';
}
import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
@Component({
selector: 'app-document-view',
template: `
`,
})
export class DocumentViewComponent implements OnInit {
documentHtml: string = '';
constructor(private http: HttpClient) {}
ngOnInit() {
this.http.get('/api/document').subscribe((document: any) => {
this.documentHtml = document.content;
});
}
}
其中,文档内容在服务器端可以用如下方式表示:
{
"title": "Document title",
"content": "This is the document content.
"
}