我想添加一些文字showlist.component.html,我showlist.component.ts代碼下面給出了,我不知道我該如何使用document.body
在角2.請指導如何document.body的注入在角2
import { Component, OnInit } from '@angular/core';
import { DOCUMENT } from '@angular/platform-browser';
@Component({
selector: 'app-showlist',
templateUrl: './showlist.component.html',
styleUrls: ['./showlist.component.css']
})
export class ShowlistComponent implements OnInit {
public myname = "saurabh";
constructor() { }
ngOnInit() {
//this.myname.appendTo(document.body);
document.body(this.myname);
//document.write(this.myname);
}
}
你_can_使用完全一樣的。 'document.body'返回'
' HTML元素。在你上面的例子中,'document.write(this.myname);'應該用'saurabh'替換所有的主體內容。如果你想引用一個特定的元素,請檢查這個[SO帖子](https://stackoverflow.com/a/35209681/3777524) – helllomatt