[Angular] Angular CDK Intro
1. Installl latest @angular/cli:
sudo npm i -g @angular/cli@next
The version I used is:6.0.0-rc.10
2. Create a new application:
ng new cdk-demo --routing
3. Install material and cdk packages:
Here need to add @next, because by the time I tried the application, v6 angular is not released yet.
npm install --save @angular/material@next @angular/cdk@next
4. Using 'ng add' to add material to the application:
ng add @angular/material
This command did some changes to the project, add some necessary code and files, which makes the whole process lot easier.
5. Update some code:
app.module.ts:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { MatCheckboxModule } from '@angular/material'; // <-- added
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
AppRoutingModule,
BrowserAnimationsModule,
MatCheckboxModule, // <-- added
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
app.component.html:
<mat-checkbox>Toggle</mat-checkbox>
Then you should be able to see a toggle element on the page.
The progress was much better than before.
But even more awesome stuff is the following.
6. Genearte a material based component by using cli:
ng g @angular/material:materialNav --name=main-nav
Then just use it in the app.component.html:
<main-nav></main-nav>

We can also do:
ng g @angular/material:material-table --name=main-table
ng g @angular/material:material-dashboard --name=main-dash
Then use it inside the main-nav we have just created:<mat-sidenav-container class="sidenav-container">
<mat-sidenav
#drawer
class="sidenav"
fixedInViewport="true"
[attr.role]="isHandset ? 'dialog' : 'navigation'"
[mode]="(isHandset | async)!.matches ? 'over' : 'side'"
[opened]="!(isHandset | async)!.matches">
<mat-toolbar color="primary">Menu</mat-toolbar>
<mat-nav-list>
<a mat-list-item href="#">Link 1</a>
<a mat-list-item href="#">Link 2</a>
<a mat-list-item href="#">Link 3</a>
</mat-nav-list>
</mat-sidenav>
<mat-sidenav-content>
<mat-toolbar color="primary">
<button
type="button"
aria-label="Toggle sidenav"
mat-icon-button
(click)="drawer.toggle()"
*ngIf="(isHandset | async)!.matches">
<mat-icon aria-label="Side nav toggle icon">menu</mat-icon>
</button>
<span>Application Title</span>
</mat-toolbar> <main-dash></main-dash> <!-- added --> </mat-sidenav-content>
</mat-sidenav-container>
[Angular] Angular CDK Intro的更多相关文章
- [Angular 2] Directive intro and exportAs
First, What is directive, what is the difference between component and directive. For my understandi ...
- [Angular] Angular Elements Intro
Make sure install the latest Angular v6 with Angular CLI. Checkout ght Github for the code. 1. Creat ...
- [Angular 2] Simple intro Http
To use http, we need to import the HTTP_PROVIDER, so that we can inject http to other component: imp ...
- Angular - - angular.Module
angular.Module Angular模块配置接口. 方法: provider(name,providerType); name:服务名称. providerType:创建一个服务的实例的构造函 ...
- Angular - - angular.injector、angular.module
angular.injector 创建一个injector对象, 调用injector对象的方法可用于获取服务以及依赖注入. 格式:angular.injector(modules); modules ...
- Angular - - Angular数据类型判断
angular.isArray 判断括号内的值是否为数组. 格式:angular.isArray(value); value: 被判断是否为数组的值. ------------------------ ...
- Angular - - angular.uppercase、angular.lowercase、angular.fromJson、angular.toJson
angular.uppercase 将指定的字符串转换成大写 格式:angular.uppercase(string); string:被转换成大写的字符串. 使用代码: var str = &quo ...
- Angular - - angular.bind、angular.bootstrap、angular.copy
angular.bind 返回一个调用self的函数fn(self代表fn里的this).可以给fn提供参数args(*).这个功能也被称为局部操作,以区别功能. 格式:angular.bind(se ...
- Angular - - angular.element
angular.element 将DOM元素或者HTML字符串一包装成一个jQuery元素. 格式:angular.element(element); element:包装成jquery对象的html ...
随机推荐
- aspectc中this可以获取的东西
this->kind 操作类型 this->targetName 被调用函数名称 this->funcName 调用函数名称 this->argsCount 参数个数 thi ...
- hdu5249
这个是去年astar的题~ 标准做法主席树,然而渣渣并不会(我确实叫zhazha...), 所以,他先离线,离散化,然后树状数组+二分水过了.... 离线的目的主要是为了离散化,剩下的就和用一个树状数 ...
- HTML中常用的颜色词汇
white (白色). black(黑色) . blue(蓝色) . green(绿色) .red(红色) .yellow(黄色) . pink(粉色).gray(灰色).brown(棕色). gre ...
- NPM 国内镜像使用方法
npm官方站点: http://www.npmjs.org/ 本文使用国内镜像地址: http://www.cnpmjs.org/ 搜索镜像:https://npm.taobao.org/ 具体方法: ...
- BZOJ 1877 拆点费用流
思路: 呃 水题不解释 行么,, //By SiriusRen #include <queue> #include <cstdio> #include <cstring ...
- vue 使用localStorage保存页面变量到浏览器变量中
const STORAGE_KEY = 'todos-vuejs'//定义常量保存键值 export default{ fetch(){ return JSON.parse(window.localS ...
- Elasticsearch中的segment理解
https://blog.csdn.net/smithallenyu/article/details/52789872 参照图 https://www.cnblogs.com/smile361/p/7 ...
- Android开机图片替换
Android开机图片替换 Android从启动到进入Launcher一共会展示三张图片,如果只是更换静态图则更换这三张图片即可,要想换成动画那就要另外操作. 首先查找这个文件: /bootab ...
- The as! Operator
Prior to Swift 1.2, the as operator could be used to carry out two different kinds of conversion, de ...
- jq遍历table 下的 td 添加类
<script> $('#btntb').click(function () { $('#tab tr').each(function (i) { // 遍历 tr $(this).chi ...