Angular 6-从动态编译的HTML获取元素

时间:2019-05-13 15:56:04

标签: angular typescript p3x-angular-compile

我有从外部API调用返回的HTML字符串。我想编译该HTML字符串并通过id'test-input'获得一个已编译的htmlElement。从DOM获取元素时,我总是得到null或未定义。我正在使用p3x-angular-compile plugin的库:

我使用了ElementRef并在nativeElement上尝试使用querySelector。仍然为空。

this.template = '<div id="test-input"><input type="text"></div>';

期望的是,一旦渲染并编译了此模板,我需要该元素以继续进行其他操作。

0 个答案:

没有答案