我试图使用Angular2向div添加一些子元素.我知道我可以使用@ViewChild获取元素但是我怎样才能真正将一些html代码附加到DOM中?
我想要做的是“模仿”JQuery追加功能.在Angular2中有没有办法做到这一点?
非常感谢你的帮助!
这是我的组件:
import { Component, ViewChild, ElementRef } from '@angular/core';
@Component({
moduleId: module.id,
selector: 'my-selector',
template: `
teste do html builder
add`,
})
export class BuilderComponent {
@ViewChild('builder') builder:ElementRef;
ngAfterViewInit() {
console.log(this.builder.nativeElement.innerHTML);
}
addRow() {
let htmlText = `
div inside parent - html builder
this.builder.nativeElement.append(htmlText); (???)
}
}