Angular17(2):angular项目中使用NG-ZORRO

1、使用Angular CLI创建空项目

 ng new angular-admin-web --style=scss

2、执行ng add ng-zorro-antd命令安装

(1)ng add ng-zorro-antd

在angular项目下运行命令 ng add ng-zorro-antd 跟随选项便可完成初始化配置,包括引入国际化文件,导入模块,引入样式文件等工作。

官网脚手架 | NG-ZORRO

 ng add ng-zorro-antd

(2)页面效果

3、手动安装

(1)安装依赖

npm install ng-zorro-antd --save

(2)引入样式

在src/styles.scss中引入基本样式

@import "../node_modules/ng-zorro-antd/ng-zorro-antd.min.css";

4、在组建中按需引入模块使用

welcome.component.html

<button nz-button nzType="primary" (click)='clickHandle()'>按钮</button>
<input type="text" nz-input [(ngModel)]="inputValue" placeholder="请输入" />

welcome.component.ts

import { Component } from '@angular/core';
// 使用ngModel实现数据双向绑定需要引入该模块
import { FormsModule } from '@angular/forms';
// 引入所需模块
import { NzButtonModule } from 'ng-zorro-antd/button';
import { NzInputModule } from 'ng-zorro-antd/input';

@Component({
  selector: 'app-welcome',
  standalone: true,
  imports: [ FormsModule, NzButtonModule, NzInputModule ],
  templateUrl: './welcome.component.html',
  styleUrls: ['./welcome.component.scss']
})
export class WelcomeComponent {

  inputValue = '';

  clickHandle() {
    console.log('click', this.inputValue);
  }

}

注意:ngModel指令实现了表单元素(如输入框、复选框等)与应用程序数据之间的双向绑定。在angular中使用ngModel时,需要确保已经将FormsModule或ReactiveFormsModule导入到Angular的组件模块中。

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值