gpt4 book ai didi

angular - 如何在 Angular2 中使用@ViewChildren?

转载 作者:太空狗 更新时间:2023-10-29 17:15:29 26 4
gpt4 key购买 nike

<分区>

在我的 home.html 中:

<p #pmessage>msg 1</p>
<p #pmessage>msg 2</p>
<p #pmessage>msg 3</p>
<p #pmessage>msg 4</p>

在我的 home.ts 中:

export class HomePage {
@ViewChildren('pmessage') pMessages;

constructor() {
//using first works, result <p>msg 1</p>
console.log(this.pMessages.first.nativeElement);
//using last also works, result <p>msg 4</p>
console.log(this.pMessages.last.nativeElement);
//How can I get the two in the middle? i.e <p>msg 2</p> and <p>msg 3</p>
//this isn't working
console.log(this.pMessage[1].nativeElement);
//this either isn't working
console.log(this.pMessage.1.nativeElement);
}
}

请帮忙。谢谢。

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com