我想添加一些文字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