【发布时间】:2019-06-26 02:54:04
【问题描述】:
我正在尝试专注于垫卡列表中的特定卡
但我不断收到错误
无法读取未定义的属性“焦点”
应在单击按钮时添加金色轮廓
import { Component, OnInit, QueryList, ElementRef, ViewChildren } from '@angular/core';
/**
* @title Basic cards
*/
@Component({
selector: 'card-overview-example',
templateUrl: 'card-overview-example.html',
styleUrls: ['card-overview-example.css'],
})
export class CardOverviewExample implements OnInit {
comments: number[];
@ViewChildren("commentCard") commentCardList: QueryList<ElementRef>;
ngOnInit() {
this.comments = [1, 2, 3, 4, 5, 6, 7, 8];
}
focus() {
const elementRef = this.commentCardList.find((item, index) => index === 4);
elementRef.nativeElement.focus();
//this.commentCardList[4].nativeElement.focus();
}
}
【问题讨论】:
-
您是否在评论卡中使用模板参考或 ID?
-
@AjayReddy 检查 stackblitz 我之前放错了链接
标签: angular typescript angular-material