angular登录按钮输入框监听

说明:angular实现简单的登录页面,监听输入框的值,打印出来,按钮监听,打印数据

效果图:

step1:E:\projectgood\ajnine\untitled4\src\app\app.config.ts

javascript 复制代码
import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core';
import { provideRouter } from '@angular/router';
import { provideAnimations } from '@angular/platform-browser/animations';

import { routes } from './app.routes';

export const appConfig: ApplicationConfig = {
  providers: [provideZoneChangeDetection({ eventCoalescing: true }), provideRouter(routes), provideAnimations()]
};

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

javascript 复制代码
import {Component, OnInit} from '@angular/core';
import {MatButtonModule} from '@angular/material/button';
import {MatInputModule} from '@angular/material/input';
import {FormsModule} from '@angular/forms';

@Component({
  selector: 'app-user',
  standalone: true,
  imports: [MatButtonModule, MatInputModule, FormsModule],
  templateUrl: './user.component.html',
  styleUrl: './user.component.css'
})
export class UserComponent implements OnInit {
  todos: Todo[] = [];
  dialogData: Todo = {task: '', description: ''};

  getClick(name: string) {
    console.log('you click this button')
    console.log(name)
    names = name
  }

  getLoginClick(name: string) {
    console.log(this.dialogData.task, this.dialogData.description)
  }

  animal() {
    return names
  }

  protected readonly names = names;

  ngOnInit(): void {
  }
}

var names = ''

interface Todo {
  task: string;
  description: string;
}

step3:

xml 复制代码
<p>欢迎来到登录页!</p>
<button style="background: deepskyblue;color: white" mat-button (click)="getClick('测试数据123')">Basic</button>
<button style="margin-left:50px;background: red;color: white" mat-button (click)="getLoginClick('测试数据456')">登录
</button>

<li>
  You chose: <em>{{ animal() }}</em>
</li>

<mat-form-field>
  <input matInput placeholder="Task" [(ngModel)]="dialogData.task">
</mat-form-field>
<mat-form-field style="margin-left: 50px">
  <input matInput placeholder="Description" [(ngModel)]="dialogData.description">
</mat-form-field>

end

相关推荐
starrysky8105 天前
一个 JSON 解析错误,搞垮了整个进程池?——requests JSONDecodeError + BrokenProcessPool 排障实录
angular.js
starrysky8105 天前
小模型反而爆显存?Qwen2.5-VL 3B vs 7B 的 vLLM 显存真相——多模态 Profiling 机制深度拆解
angular.js
starrysky8109 天前
THP 透明大页导致数据库延迟从 2ms 飙升到 2000ms——khugepaged 内存压缩风暴排查实录
angular.js
starrysky81012 天前
多Agent通信架构实战:从NATS消息总线到五大编排模式的生产落地——Agent通信协议篇
angular.js
starrysky81012 天前
RecursionError: maximum recursion depth exceeded —— 你的函数调用链,踩穿了 CPython 的安全气囊
angular.js
starrysky81014 天前
MemAvailable 还有 29GB,系统却报内存压力?——Ubuntu 24.04 CIFS 内核 Page Cache 泄漏排查实录
angular.js
starrysky81014 天前
KeyError: 'xxx' —— 字典里没这个键,但你的代码以为有
angular.js
starrysky81014 天前
FP8量化实战:vLLM与SGLang部署DeepSeek显存减半、吞吐翻倍——Agent推理引擎篇(二)
angular.js
starrysky81014 天前
vLLM与SGLang启动参数调优实战:从默认配置到生产级吞吐量翻倍——Agent推理引擎篇
angular.js
starrysky81014 天前
【03】ImportError: cannot import name 'X' —— 模块在,名字没了
angular.js