APIs used Simple ExampleRender subcomponents in a list, click on a subcomponent to notify the parent component to perform an operation person.tsexport interface Person { name: string; age: number; sex: string; } Parent Componentimport { Component, OnInit } from '@angular/core'; import { Person } from './person'; @Component({ selector: 'app-comp-parent', template: ` <app-comp-child *ngFor="let person of personList" (itemClick)="onItemClick($event)" [data]="person" ></app-comp-child> `, }) export class CompParentComponent implements OnInit { personList: Person[] = [ { name: '张三', age: 21, sex: '男' }, { name: 'Li Si', age: 25, sex: 'Male' }, { name: '李莉', age: 20, sex: '女' }, ]; constructor(){ } ngOnInit(): void { } onItemClick(item: Person){ console.log('click-person: ', item); } } Subcomponentsimport { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; import { Person } from './person'; @Component({ selector: 'app-comp-child', template: ` <div (click)="itemClick.emit(data)"> Name: {{ data.name }} Age: {{ data.age }} Sex: {{ data.sex }} </div> `, }) export class CompChildComponent implements OnInit { @Input() data!: Person; @Output() itemClick = new EventEmitter(); constructor(){ } ngOnInit(): void { } } Effect SummarizeThis article ends here. I hope it can be helpful to you. I also hope you can pay more attention to more content on 123WORDPRESS.COM! You may also be interested in:
|
<<: Pure CSS code to achieve drag effect
>>: A detailed introduction to Linux memory management and addressing
Table of contents Why use day.js Moment.js Day.js...
Regarding how to create this thin-line table, a s...
Table of contents As a global variable Variable H...
Tomcat is widely known as a web container. It has...
Automated project deployment is more commonly use...
Table of contents What is multi-environment confi...
The vue project built with cli3 is known as a zer...
Recently I used vue to learn to develop mobile pr...
1. The startup menu is to move the cursor to the ...
question Adding the type of uploaded file in acce...
How to modify the style of the el-select componen...
About Nginx, a high-performance, lightweight web ...
CentOS7 is used here, and the kernel version is [...
1. Environment version Docker version 19.03.12 ce...
<input> is used to collect user information ...