Mastering Angular UI: Unlocking the Power of Ng Zorro
Tags: angular, antdesign, ngzorro, beginners
Published: 2023-06-16 04:05:11

## **Introduction**
A strong and well-liked JavaScript|TypeScript framework for creating web apps is called Angular. It offers a wide range of tools and capabilities and adheres to the component-based design. Single-page applications (SPAs) that are dynamic and responsive and provide a smooth user experience can be made with Angular. It enables dependency injection and two-way data binding and provides extensive routing and testing capabilities. Google maintains Angular, and a thriving community actively participates in its growth and support.

## **Ng-Zorro**
A complete library of UI components for Angular apps is called NgZorro. It includes a large selection of pre-built elements that can be quickly integrated into your project, such as buttons, forms, modals, tables, and more. NgZorro gives your application a unified and professional appearance by adhering to contemporary design concepts. Additionally, it has more sophisticated features like support for internationalisation (i18n) and improvements to accessibility. A popular option for Angular developers, NgZorro is regularly maintained, well-documented, and supported by a thriving community.

##**Table of contents**

[1.Installing Angular CLI in local environment](#chapter-1)
[2.Creating new project with Angular](#chapter-2)
[3.Installing ng-zorro-antd](#chapter-3)
[4.Creating a separate module for importing components](#chapter-4)
[5.Serving the project](#chapter-5)

## **1.Installing Angular CLI in local environment** <a name="chapter-1"></a>
During development, there are a number of engineering requirements, such as compiling, debugging, proxying, and packaging TypeScript code. We strongly advise you to use the Angular official CLI @angular/cli to develop your project. Here is a little example to make my point clear.

```javascript
$ npm install -g @angular/cli
# Or if you use yarn
$ yarn global add @angular/cli
```
From the above line of code,we install angular CLI which helps to run any Angular application in the local environment.

## **2.Creating new project with Angular** <a name="chapter-2"></a>
The following command enables @angular/cli to build a PROJECT-NAME folder with all necessary dependencies within the current directory.

```javascript
$ ng new PROJECT-NAME
```
@angular/cli will run npm install or yarn after a project is created. You can run npm install or yarn by yourself if it fails

## **3.Installing ng-zorro-antd** <a name="chapter-3"></a>
After changing the directory to the newly created project, you can automatically run the following commands to initialize the project's configuration, including importing i18n files and stylesheets and loading initial modules.

```Javascript
$ cd PROJECT-NAME
$ ng add ng-zorro-antd
```

![Terminal](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dv4wt23wr9t2a3dhqfvv.png)
Now **Ant-design** is initialised to the project.The Folder structure of the project look like the following picture.

![Folder structure](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8rtw1xw3ra8qefo9thx9.png)

## **4.Creating a separate module for importing components** <a name="chapter-4"></a>
Create a separate file inside the App folder called NgZorro.module.ts

> NgZorro.module.ts

```Javascript
import { NgModule } from '@angular/core';
import { NzIconModule } from 'ng-zorro-antd/icon';
import { NzButtonModule } from 'ng-zorro-antd/button';

@NgModule({
  exports: [
    NzIconModule,
    NzButtonModule,
  ],
})
export class NgZorroModule {}
```
In the above file, we can import whatever components from the NgZorro module using [the official documentation](https://ng.ant.design/components/overview/en)
The separate file is created for organising the folder structure.
Next the above declared module must be imported in the app.module.ts file for using it in the template files and its child component templates.

> app.module.ts
```Javascript
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';

import { AppComponent } from './app.component';
import { NZ_I18N } from 'ng-zorro-antd/i18n';
import { en_US } from 'ng-zorro-antd/i18n';
import { registerLocaleData } from '@angular/common';
import en from '@angular/common/locales/en';
import { FormsModule } from '@angular/forms';
import { HttpClientModule } from '@angular/common/http';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

import { NgZorroModule } from './ngZorro.module';

registerLocaleData(en);

@NgModule({
  declarations: [AppComponent],
  imports: [
    NgZorroModule,
    BrowserModule,
    FormsModule,
    HttpClientModule,
    BrowserAnimationsModule,
  ],
  providers: [{ provide: NZ_I18N, useValue: en_US }],
  bootstrap: [AppComponent],
})
export class AppModule {}
```
The NgZorro components are now ready to use it in the templates.
Let's take an example of creating a button.

> app.component.html

```Javascript
<!-- NG-ZORRO -->
<button nz-button nzType="primary">Primary Button</button>
<button nz-button nzType="default">Default Button</button>
<button nz-button nzType="dashed">Dashed Button</button>
<button nz-button nzType="text">Text Button</button>
<a nz-button nzType="link">Link Button</a>
```
## **5.Serving the project** <a name="chapter-5"></a>

Your project is now ready to run. After running the following command, a welcome page will be displayed in your browser.

```Javascript
# Either you use the command
$ng serve
#or
$npm start
```

By default, the project will be opened in the url
> http://localhost:4200


![http://localhost:4200](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mkz8d5rj3grl5qiko5ao.png)

Now you have successfully added NgZorro to Angular project.
Now you work on projects in lightning speed having reference with [the offical documentation](https://ng.ant.design/components/overview/en).
I hope this post helps you integrating NgZorro with Angular.
Subscribe to my account for getting more useful information like this.
Happy coding...😉