Home > Web Front-end > JS Tutorial > Detailed explanation of material installation and use in Angular

Detailed explanation of material installation and use in Angular

青灯夜游
Release: 2021-03-11 18:17:34
forward
4547 people have browsed it

This article will introduce to you how to install and use material in Angular. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

Detailed explanation of material installation and use in Angular

Related recommendations: "angular Tutorial"

1. Introduction to Angular

Angular is an open source web front-end framework developed by Google. It was born in 2009, created by Misko Hevery and others, and later acquired by Google. It is an excellent front-end JS framework that has been used in many Google products.

According to the statistics of the number of projects (1.x, 2.x, 4.x, 5.x, 6.x, 7.x, 8.x, 9.x) are now online The most used framework.

Angular is based on TypeScript and compared to react and vue, Angular is more suitable for medium and large enterprise-level projects.

The latest version of angular is angular9.x on December 25, 2019. According to the official introduction, Angular will be updated with a version every few months. The usage is the same for all Angular versions after Angular2.x. This tutorial is also applicable to Angular7.x
, Angular8.x, Angular9.x and other future versions...

Detailed explanation of material installation and use in Angular

2. Installation and use of Angular material

material official document: https://material.angular.io
material official document (Chinese version): https://material.angular.cn/components/categories

(1) Angular material installation

1. First create a new project

2. Enter the following three sentences in the created project to complete the installation of material (which project the material belongs to depends on which project it is used in)

  (1)npm install --save @angular/cdk@8.1.2 @angular/material@8.1.2 @angular/animations@8.2.8 hammerjs
  (2)npm install --save @angular/flex-layout@8.0.0-beta.26
  (3)ng add @angular/material
Copy after login

(2) Angular material usage

1. Introduce the corresponding material module in app.module.ts

2. Use of newly created components material

Here you can refer to the examples in the official documents (you can check it now and use it, there are many examples)

Detailed explanation of material installation and use in Angular
Detailed explanation of material installation and use in Angular
Detailed explanation of material installation and use in Angular
3. My operation is to create a material custom module, store the imported material module in it, and then add import{MaterialModule}from'./material/material/ in app.module.ts material.module';, then create a new component, copy the code from the official document and run it.

Share the code in my material.module.ts here for reference (the material module introduced here is incomplete and needs to be added according to the actual situation)

 import { NgModule } from '@angular/core';
 import { CommonModule } from '@angular/common'; 
 import { 
    MatCardModule,
    MatFormFieldModule,
    MatInputModule,
    MatTableModule,
    MatSortModule,
    MatPaginatorModule,
    MatSliderModule,
    MatOptionModule,
    MatAutocompleteModule,
    MatSlideToggleModule,
    MatCheckboxModule,
    MatSelectModule,
    MatRadioModule,
    MatButtonModule,
    MatDatepickerModule,
    MatNativeDateModule,
    MatIconModule,
    MatDialogModule,} from '@angular/material';
 import { ReactiveFormsModule,FormsModule } from '@angular/forms';

 const Material = [
    MatCardModule,
    MatFormFieldModule,
    MatInputModule,
    ReactiveFormsModule,
    MatTableModule,
    MatSortModule,
    MatPaginatorModule,
    MatSliderModule,
    MatOptionModule,
    MatAutocompleteModule,
    MatSlideToggleModule,
    MatCheckboxModule,
    FormsModule,
    MatSelectModule,
    MatRadioModule,
    MatButtonModule,
    MatDatepickerModule,
    MatNativeDateModule,
    MatIconModule,
    MatDialogModule,];@NgModule({
  declarations: [],
  imports: [
    CommonModule,
    Material  ],
  exports: [Material]})export class MaterialModule { }
Copy after login

For more programming-related knowledge, please visit: programming video! !

The above is the detailed content of Detailed explanation of material installation and use in Angular. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template