作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这不是重复的。我已经完成了我的研究。如果您仍然觉得这不是一个好问题,请在评论中写下答案并删除问题。我想做的是将索引值从 HTML 元素传递到组件。
<ul *ngFor="let person of persons; let i= index" [index]="i">
//上面^^^^^ View 的组件
class appComponent{
@Input() index; // this should get the value of index; but it gives undefined
}
最佳答案
不能在同一个组件上使用@Input
,
你可以这样做
<div *ngFor="let person of persons;let i = index">
<div (click)="getIndex(i)">
</div>
<div>`
然后在TS中
getIndex(index){
console.log(index);//clicked index
}
关于angular - 如何将索引传递给组件 angular 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46793645/
我是一名优秀的程序员,十分优秀!