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
Docker Compose Docker Compose is a tool for defin...
Use canvas to write a colorful clock! 1. Title (1...
Table of contents 1. Implementation 2. Problems 3...
Recently, I have implemented such an effect: clic...
Windows: Support NTFS, FAT Linux supports file fo...
This article uses Vue to simply implement the cha...
Install Nginx on Docker Nginx is a high-performan...
The cursor size in the input box is inconsistent T...
The steps are as follows 1. Create a docker group...
MySQL UTF-8 encoding MySQL has supported UTF-8 si...
What are :is and :where? :is() and :where() are p...
Table of contents 1. Nginx implements load balanc...
Effect Need environment vue elementUI Drag and dr...
download Download address: https://redis.io/downl...
1. Send effect HTML <div id="send-btn&quo...