美文网首页
NG-Zorro 在 Angular中的应用实例

NG-Zorro 在 Angular中的应用实例

作者: 全栈开发之道 | 来源:发表于2018-07-19 23:03 被阅读0次

说明

亮点: 该实例,用到了 子模块的概念。 根据网页的layout布局,把相关的 components 组建成一个 module。 一个 app module 由多个 子module 组成。 这就是更深层次的 module 框架的应用。

在该实例中,我创建了 3个 独立的 module。

创建工程,并验证开发环境

ng new myLogin
cd myLogin
ng serve --o

安装 ng-zorro

npm install ng-zorro-antd --save

angular.json 文件,导入 ng-zorro

"styles": [
              "src/styles.css" ,
              "node_modules/ng-zorro-antd/src/ng-zorro-antd.css"
            ],

app.module.ts 文件 导入 NgZorroAntdModule

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { NgZorroAntdModule } from 'ng-zorro-antd';

import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    NgZorroAntdModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

验证 ng-zorro 是否生效, 在 app.component.html 添加代码,如下:

<h2>Buttons</h2>
<button nz-button  [nzType]="'primary'">primary</button>
<button nz-button  [nzType]="'dashed'">dashed</button>
<button nz-button  [nzType]="'default'">default</button>
<button nz-button  [nzType]="'danger'">danger</button>
<button nz-button  [nzShape]="'default'">defaultShape</button>
<button nz-button  [nzShape]="'circle'">O</button>
<button nz-button  [nzSize]="'large'">L</button>
<button nz-button  [nzSize]="'default'">M</button>
<button nz-button  [nzSize]="'small'">S</button>
<button nz-button  [nzGhost]="true">L</button>
<button nz-button  [nzLoading]="true">L</button>

创建 component

ng g c components/login --spec=false

手动创建module ,一个module 包含多个 components。

最终实现的效果

image.png

相关文章

网友评论

      本文标题:NG-Zorro 在 Angular中的应用实例

      本文链接:https://www.haomeiwen.com/subject/cytxmftx.html