TypeScript - Append HTML to container element in Angular 2

后端 未结 5 708
鱼传尺愫
鱼传尺愫 2020-12-04 14:39

What I want to do, is simply append some html on an element. I checked some links, and i find different confusing/non-working/non-recomended/etc solutions.

Using jav

5条回答
  •  [愿得一人]
    2020-12-04 15:01

    When working with Angular the recent update to Angular 8 introduced that a static property inside @ViewChild() is required as stated here and here. Then your code would require this small change:

    @ViewChild('one') d1:ElementRef;
    

    into

    // query results available in ngOnInit
    @ViewChild('one', {static: true}) foo: ElementRef;
    

    OR

    // query results available in ngAfterViewInit
    @ViewChild('one', {static: false}) foo: ElementRef;
    

提交回复
热议问题