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

相关推荐
DEMO派2 天前
CSS优先级规则以及如何提升优先级方案详解
前端·javascript·css·vue.js·reactjs·html5·angular.js
TeamDev6 天前
基于 Angular UI 的 C# 桌面应用
前端·后端·angular.js
DevUI团队9 天前
🔥Angular高效开发秘籍:掌握这些新特性,项目交付速度翻倍
前端·typescript·angular.js
TTt10220712 天前
ng老狗的Vue 3 响应式系统源码分享
angular.js
Zhen (Evan) Wang13 天前
.NET 8 API +Angular 16 + Mysql利用docker compose发布
mysql·.net·angular.js
再花1 个月前
在Angular中实现基于nz-calendar的日历甘特图
前端·angular.js
爱学习的小康1 个月前
angular MicroApp微服务改造
前端·微服务·angular.js
码界奇点1 个月前
基于Spring MVC与AngularJS的API接口管理系统设计与实现
spring·毕业设计·yapi·mvc·angular.js·源代码管理
Highcharts.js1 个月前
官方文档|Angular 框架集成 Highcharts Dashboards
前端·javascript·angular.js·highcharts·看板·使用文档·dashboards