Angular6新特性之Angular Material
Angular Material是包含Navigation/Dashboard/Table三種圖形類型,這篇文章中將會了解一些其使用的方式。
準(zhǔn)備:安裝Material
進(jìn)入到上篇文章創(chuàng)建的demo2,使用ng add進(jìn)行安裝
liumiaocn:demo2 liumiao$ pwd /tmp/trainings/angualr/demo2 liumiaocn:demo2 liumiao$
安裝命令:ng add @angular/material
liumiaocn:demo2 liumiao$ ng add @angular/material Installing packages for tooling via yarn. yarn add v1.7.0 [1/4] ? Resolving packages... [2/4] ? Fetching packages... [3/4] ? Linking dependencies... warning " > @angular/material@6.4.0" has unmet peer dependency "@angular/cdk@6.4.0". [4/4] ? Building fresh packages... success Saved lockfile. success Saved 1 new dependency. info Direct dependencies └─ @angular/material@6.4.0 info All dependencies └─ @angular/material@6.4.0 ✨ Done in 13.02s. Installed packages for tooling via yarn. UPDATE package.json (1374 bytes) UPDATE angular.json (3785 bytes) UPDATE src/app/app.module.ts (423 bytes) UPDATE src/index.html (469 bytes) UPDATE src/styles.css (165 bytes) liumiaocn:demo2 liumiao$
確認(rèn)package的變化
安裝之前對package.json做了備份,可以看出此次操作有何變化
liumiaocn:demo2 liumiao$ diff package.json package.json.org 20d19 < "@angular/material": "^6.4.0", 26,27c25 < "zone.js": "^0.8.26", < "@angular/cdk": "^6.2.0" --- > "zone.js": "^0.8.26" 29a28 > "@angular/compiler-cli": "^6.0.3", 30a30 > "typescript": "~2.7.2", 32d31 < "@angular/compiler-cli": "^6.0.3", 47,48c46 < "tslint": "~5.9.1", < "typescript": "~2.7.2" --- > "tslint": "~5.9.1" liumiaocn:demo2 liumiao$
由于diff命令自身的限制,一些沒有變化的內(nèi)容也被列了出來,確認(rèn)之后發(fā)現(xiàn)@angular/material和@angular/cdk是添加的內(nèi)容
Material Navigation
使用Material 創(chuàng)建Navigation只需要如下的命令即可
創(chuàng)建命令:ng generate @angular/material:material-nav –name 名稱
接下來我們創(chuàng)建一個名為mynav的Material Navigation
liumiaocn:demo2 liumiao$ ng generate @angular/material:material-nav --name mynav CREATE src/app/mynav/mynav.component.css (129 bytes) CREATE src/app/mynav/mynav.component.html (948 bytes) CREATE src/app/mynav/mynav.component.spec.ts (698 bytes) CREATE src/app/mynav/mynav.component.ts (577 bytes) UPDATE src/app/app.module.ts (793 bytes) liumiaocn:demo2 liumiao$
確認(rèn)selector為app-mynav
liumiaocn:demo2 liumiao$ cat src/app/mynav/mynav.component.ts import { Component } from '@angular/core'; import { BreakpointObserver, Breakpoints, BreakpointState } from '@angular/cdk/layout'; import { Observable } from 'rxjs'; import { map } from 'rxjs/operators'; @Component({ selector: 'app-mynav', templateUrl: './mynav.component.html', styleUrls: ['./mynav.component.css'] }) export class MynavComponent { isHandset$: Observable<boolean> = this.breakpointObserver.observe(Breakpoints.Handset) .pipe( map(result => result.matches) ); constructor(private breakpointObserver: BreakpointObserver) {} } liumiaocn:demo2 liumiao$
替換app.component.html的內(nèi)容,確認(rèn)Material Navigation的運(yùn)行狀況
liumiaocn:demo2 liumiao$ cat src/app/app.component.html <app-mynav></app-mynav> liumiaocn:demo2 liumiao$
運(yùn)行ng serve
liumiaocn:demo2 liumiao$ ng serve ** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ ** ...省略 ℹ 「wdm」: Compiled successfully.
確認(rèn)Material Navigation運(yùn)行頁面
可以看到,缺省生成的Material Navigation就是一個Sidebar的菜單布局
Material Table
創(chuàng)建命令:ng generate @angular/material:material-table –name 名稱
創(chuàng)建名為mytable的Material Table:
liumiaocn:demo2 liumiao$ ng generate @angular/material:material-table --name mytable CREATE src/app/mytable/mytable-datasource.ts (3360 bytes) CREATE src/app/mytable/mytable.component.css (0 bytes) CREATE src/app/mytable/mytable.component.html (857 bytes) CREATE src/app/mytable/mytable.component.spec.ts (618 bytes) CREATE src/app/mytable/mytable.component.ts (701 bytes) UPDATE src/app/app.module.ts (993 bytes) liumiaocn:demo2 liumiao$ liumiaocn:demo2 liumiao$ grep app- src/app/mytable/mytable.component.ts selector: 'app-mytable', liumiaocn:demo2 liumiao$
替換app.component.html并運(yùn)行ng serve
liumiaocn:demo2 liumiao$ cat src/app/app.component.html <app-mytable></app-mytable> liumiaocn:demo2 liumiao$
確認(rèn)Material Table運(yùn)行頁面,頂部對table可以進(jìn)行排序操作
滑動到尾部可以看到具有分頁的功能
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,謝謝大家對腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請查看下面相關(guān)鏈接
相關(guān)文章
angular2中router路由跳轉(zhuǎn)navigate的使用與刷新頁面問題詳解
這篇文章主要給大家介紹了angular2中router路由跳轉(zhuǎn)navigate的使用與刷新頁面問題的相關(guān)資料,文中介紹的非常詳細(xì),對大家具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起看看吧。2017-05-05Angular Excel 導(dǎo)入與導(dǎo)出的實現(xiàn)代碼
這篇文章主要介紹了Angular Excel 導(dǎo)入與導(dǎo)出的實現(xiàn)代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-04-04Angular中點擊li標(biāo)簽實現(xiàn)更改顏色的核心代碼
這篇文章主要介紹了Angular中點擊li標(biāo)簽實現(xiàn)更改顏色的核心代碼,需要的朋友可以參考下2017-12-12微信+angularJS的SPA應(yīng)用中用router進(jìn)行頁面跳轉(zhuǎn),jssdk校驗失敗問題解決
本文主要介紹微信+angularJS的SPA應(yīng)用中用router進(jìn)行頁面跳轉(zhuǎn),jssdk校驗失敗問題解決,這里提供了詳細(xì)的操作方式,有需要的小伙伴可以參考下2016-09-09Angular基于Constructor?Parameter的依賴注入方式詳解
這篇文章主要為大家介紹了Angular基于Constructor?Parameter的依賴注入方式詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-11-11Angular+ionic實現(xiàn)折疊展開效果的示例代碼
這篇文章主要介紹了Angular+ionic實現(xiàn)折疊展開效果,本文通過實例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-07-07AngularJS使用ng-repeat遍歷二維數(shù)組元素的方法詳解
這篇文章主要介紹了AngularJS使用ng-repeat遍歷二維數(shù)組元素的方法,結(jié)合實例形式分析了AngularJS二維數(shù)組元素遍歷的相關(guān)操作技巧,需要的朋友可以參考下2017-11-11