在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML5/ angular的@ViewChild和@ViewChildren獲取不到元素

angular的@ViewChild和@ViewChildren獲取不到元素

import { Component, AfterViewInit, ViewChild, ElementRef, Renderer2, ViewChildren, QueryList } from '@angular/core';

@Component({
  selector: 'app-locations',
  templateUrl: './locations.component.html',
  styleUrls: ['./locations.component.scss']
})
export class LocationsComponent implements AfterViewInit {

  constructor(private elementRef: ElementRef, private renderer: Renderer2) { }
  @ViewChild('test', { read: ElementRef })
  public itemDiv: ElementRef;
  @ViewChildren('item')
  public itemDivs: QueryList<ElementRef>;
  public ngAfterViewInit() {
    setTimeout(() => {
      console.log('sssss', this.itemDiv);
      console.log('sssssb', this.itemDivs);
    }, 0);
  }

}
<div class="row no-gutters h-100" id="test">
  <div class="col-4 item">
    <app-locations-list></app-locations-list>
  </div>
  <div class="col-4 item">
  </div>
  <div class="col-4 item">
    One of three columns
  </div>
</div>

結(jié)果:
圖片描述
請問我代碼是哪里出了問題?新入門,請多多指教!

回答
編輯回答
不二心

html中應(yīng)該是#test, 而不是設(shè)置id

2018年8月20日 01:38