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

相关推荐
Highcharts.js2 天前
官方文档|Angular 框架集成 Highcharts Dashboards
前端·javascript·angular.js·highcharts·看板·使用文档·dashboards
聊天QQ:4877392783 天前
基于STM32F103与FPGA的伺服驱动器探索:电流环于FPGA的高效运作
angular.js
Tiam-20164 天前
安装NVM管理多版本node
vue.js·前端框架·node.js·html·es6·angular.js
黑臂麒麟5 天前
DevUI modal 弹窗表单联动实战:表格编辑功能完整实现
前端·javascript·ui·angular.js
黑臂麒麟5 天前
华为云的DevUI&Form组件实战:个人信息编辑表单完整实现
前端·javascript·ui·华为云·angular.js
柠檬水不加冰_8 天前
Angular学习记录
javascript·学习·angular.js
QQ 192263811 天前
Matlab弹道仿真软件,界面实时显示弹道,提供源码,同时提供常规弹外弹道仿真软件使用说明书...
angular.js
crary,记忆13 天前
Angular.json中的commonChunk 的作用
前端·javascript·学习·angular.js
jumu20215 天前
基于MATLAB搭建的准Z源NpC三电平逆变器拓扑,利用SVPWM调制算法,加入了中性点平衡算...
angular.js
S***428018 天前
JavaScript在Web中的Angular
前端·javascript·angular.js