Angular 2:如何通过CSS选择器在@ViewChild中查找子元素?

Angular 2: How to Find Children Element in @ViewChild by CSS Selector?

我想通过 nth-child() 选择器或 class:

更改第二个 p 的样式
import { Component, ViewChild } from '@angular/core';
@Component({
  selector: 'my-app',
  template: `
    <div #container>
        <p>para 1</p>
        <p class="my-class">para 2</p>
        <button>button 1</button>
    </div>
  `
})
export class AppComponent {
  @ViewChild('container') myDiv;
  ngAfterViewInit(){
    console.log(this.myDiv.nativeElement.children);
  } 
}

以下代码将从视图 child

中为您提供子元素
let children = this.myDiv.nativeElement.getElementsByTagName("p");

请看plunker代码

https://plnkr.co/edit/yX2jIG?p=preview