andrular输入框input监听值传递

server/2024/12/4 4:02:11/

效果图·:
在这里插入图片描述

step1: E:\projectgood\ajnine\untitled4\src\app\apple\apple.component.html
<button mat-button (click)=“openDialog()”>Open dialog

step2: E:\projectgood\ajnine\untitled4\src\app\apple\apple.component.ts

import {Component, inject} from '@angular/core';
import {MatButton, MatButtonModule} from '@angular/material/button';
import {MatDialog, MatDialogModule} from '@angular/material/dialog';
import {DialogContentExampleDialog} from './DialogContentExampleDialog';
import {async} from 'rxjs';@Component({selector: 'app-apple',standalone: true,imports: [MatButton, MatButtonModule, MatDialogModule],templateUrl: './apple.component.html',styleUrl: './apple.component.css'
})
export class AppleComponent {readonly dialog = inject(MatDialog);openDialog() {// const dialogRef = this.dialog.open(DialogContentExampleDialog);const dialogRef = this.dialog.open(DialogContentExampleDialog, {data: {url:'https://www.baidu.com',id:101},maxWidth: '100vw',panelClass: 'full-width-dialog',});/*
*     dialogRef.afterClosed().subscribe(async (result: AddMediaDialogData) => {if (!result || !result.url) {return;}
* */dialogRef.afterClosed().subscribe(result => {console.log(`Dialog result: ${result}`);});}}

step3: E:\projectgood\ajnine\untitled4\src\app\apple\dialog-content-example-dialog.html

<p style="width: 900px;" mat-dialog-title>商品修改</p>
<p style="margin-left: 20px;">{{ this.data.id }}</p><mat-form-field style="margin-left: 20px;margin-top: 10px;margin-right: 20px"><input matInput placeholder="请输入position" [(ngModel)]="dialogData.position">
</mat-form-field>
<mat-form-field style="margin-left: 20px;margin-right: 20px"><input matInput placeholder="请输入name" [(ngModel)]="dialogData.name">
</mat-form-field>
<mat-form-field style="margin-left: 20px;margin-right: 20px"><input matInput placeholder="请输入icon" [(ngModel)]="dialogData.icon">
</mat-form-field>
<mat-form-field style="margin-left: 20px;margin-right: 20px"><input matInput placeholder="请输入phone" [(ngModel)]="dialogData.phone">
</mat-form-field>
<mat-form-field style="margin-left: 20px;margin-right: 20px"><input matInput placeholder="请输入address" [(ngModel)]="dialogData.address">
</mat-form-field><button style="margin-left:20px;background: red;color: white;margin-bottom: 10px;width: 120px;" mat-button (click)="getLoginClick('测试数据456')">登录</button><button mat-flat-button [mat-dialog-close]="this.dialogData" color="primary">Add</button>

step4: E:\projectgood\ajnine\untitled4\src\app\apple\DialogContentExampleDialog.ts

import {ChangeDetectionStrategy, Component, Inject, OnInit} from '@angular/core';
import {MAT_DIALOG_DATA, MatDialogModule, MatDialogRef} from '@angular/material/dialog';
import {MatButtonModule} from '@angular/material/button';
import {FormsModule} from '@angular/forms';
import {MatFormField} from '@angular/material/form-field';
import {MatInput} from '@angular/material/input';@Component({selector: 'dialog-content-example-dialog',templateUrl: 'dialog-content-example-dialog.html',standalone: true,imports: [MatDialogModule, MatButtonModule, FormsModule, MatFormField, MatInput],changeDetection: ChangeDetectionStrategy.OnPush,
})
export class DialogContentExampleDialog implements OnInit{cancelString :string=''sureString :string=''testString :string=''todos: Todo[] = [];/** {"position": "772024102801","name": "雨林","icon": "http://e.hiphotos.baidu.com/image/pic/item/a1ec08fa513d2697e542494057fbb2fb4316d81e.jpg","phone": "13952141236","address": "成都市双流区华阳时代广场a栋701室"}* */dialogData: Todo = {position: '772024102801', name: '雨林', icon: 'http://e.hiphotos.baidu.com/image/pic/item/a1ec08fa513d2697e542494057fbb2fb4316d81e.jpg', phone: '13952141236', address: '成都市双流区华阳时代广场a栋701室'};protected readonly names = names;constructor(public dialogRef: MatDialogRef<AddMediaDialogData>, @Inject(MAT_DIALOG_DATA) public data: AddMediaDialogData) {}getClick(name: string) {console.log('you click this button')console.log(name)names = name}getLoginClick(name: string) {console.log(this.dialogData.position)console.log(this.dialogData.name)console.log(this.dialogData.icon)console.log(this.dialogData.phone)console.log(this.dialogData.address)console.log(this.data.id)this.dialogRef.close();}animal() {return names}ngOnInit(): void {this.cancelString="鲨鱼哟"this.sureString="昊昊超体"this.testString="测试超体"}onNoClick(): void {console.log(this.data.url)// this.data.url = '';this.dialogRef.close();}}export interface AddMediaDialogData {url: string;id: number;
}var names = ''interface Todo {position: string;name: string;icon: string;phone: string;address: string;
}/*
{"position": "772024102801","name": "雨林","icon": "http://e.hiphotos.baidu.com/image/pic/item/a1ec08fa513d2697e542494057fbb2fb4316d81e.jpg","phone": "13952141236","address": "成都市双流区华阳时代广场a栋701室"}一共五个输入内容输入位置输入名称输入icon输入phone输入地址
* */

end


http://www.ppmy.cn/server/140531.html

相关文章

第一章 初识Docker与容器

1、Docker定义 Docker是基于Go语言实现的开源容器项目。诞生于2013年初&#xff0c;由dotCloud公司&#xff08;后改名为 Docker Inc&#xff09;发起。 Docker的构想是要实现“Build&#xff0c;Ship and Run Any App&#xff0c;Anywhere”&#xff0c;通过对应用的封装Pac…

Maven 中央仓库地址 mvnrepository.com

下载一些 jar 包驱动&#xff0c;不需用去官网下了&#xff0c;直接去 Maven 中央仓库&#xff0c;高效、简单 Maven 中央仓库地址 https://mvnrepository.com/open-source 我们下期见&#xff0c;拜拜&#xff01;

angular实现list列表和翻页效果

说明&#xff1a;angular实现list列表和翻页效果 上一页 当前页面 下一页 效果图&#xff1a; step1: E:\projectgood\ajnine\untitled4\src\app\car\car.component.css .example-form-fields {display: flex;align-items: flex-start; }mat-list-item{background: antiquew…

力扣(leetcode)每日一题 3255 长度为 K 的子数组的能量值 II|滑动窗口

3255. Find the Power of K-Size Subarrays II 1.题干 You are given an array of integers nums of length n and a positive integer k. The power of an array is defined as: Its maximum element if all of its elements are consecutive and sorted in ascending ord…

【Python】轻松解析JSON与XML:Python标准库的json与xml模块

轻松解析JSON与XML&#xff1a;Python标准库的json与xml模块 在现代数据处理与交换中&#xff0c;JSON&#xff08;JavaScript Object Notation&#xff09;和XML&#xff08;eXtensible Markup Language&#xff09;是最常用的两种数据格式。它们广泛应用于API数据传输、配置…

【elkb】kibana后台删除索引

打开kibana后台 点击 Management ---> Index Management 找到要删除的所以点击 点击delete index 删除成功

opencv保姆级讲解——光学学符识别(OCR)(4)

光学字符识别 &#xff08;Optical Character Recognition, OCR&#xff09;是指对文本材料的图像文件进行分析识别处理&#xff0c;以获取文字和版本信息的过程。也就是说将图象中的文字进行识别&#xff0c;并返回文本形式的内容 以下是比较流行的开源的ORC识别库 Tessera…

高考:心态、时间、知识,多维度攻略让你脱颖而出

高考&#xff0c;宛如一场无声的激战&#xff0c;承载着无数莘莘学子的梦想与热望。在这激烈的竞争中&#xff0c;充分且周全的准备显得尤为关键。那么&#xff0c;高考备考究竟应从哪些方面入手&#xff1f;又有哪些行之有效的备考策略能为我们保驾护航呢&#xff1f; 一、高考…