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的更多相关文章

  1. [Angular 2] Directive intro and exportAs

    First, What is directive, what is the difference between component and directive. For my understandi ...

  2. [Angular] Angular Elements Intro

    Make sure install the latest Angular v6 with Angular CLI. Checkout ght Github for the code. 1. Creat ...

  3. [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 ...

  4. Angular - - angular.Module

    angular.Module Angular模块配置接口. 方法: provider(name,providerType); name:服务名称. providerType:创建一个服务的实例的构造函 ...

  5. Angular - - angular.injector、angular.module

    angular.injector 创建一个injector对象, 调用injector对象的方法可用于获取服务以及依赖注入. 格式:angular.injector(modules); modules ...

  6. Angular - - Angular数据类型判断

    angular.isArray 判断括号内的值是否为数组. 格式:angular.isArray(value); value: 被判断是否为数组的值. ------------------------ ...

  7. Angular - - angular.uppercase、angular.lowercase、angular.fromJson、angular.toJson

    angular.uppercase 将指定的字符串转换成大写 格式:angular.uppercase(string); string:被转换成大写的字符串. 使用代码: var str = &quo ...

  8. Angular - - angular.bind、angular.bootstrap、angular.copy

    angular.bind 返回一个调用self的函数fn(self代表fn里的this).可以给fn提供参数args(*).这个功能也被称为局部操作,以区别功能. 格式:angular.bind(se ...

  9. Angular - - angular.element

    angular.element 将DOM元素或者HTML字符串一包装成一个jQuery元素. 格式:angular.element(element); element:包装成jquery对象的html ...

随机推荐

  1. Truck History(prim)

    http://poj.org/problem?id=1789 读不懂题再简单也不会做,英语是硬伤到哪都是真理,sad++. 此题就是一个最小生成树,两点之间的权值是毎两串之间的不同字母数. #incl ...

  2. python修改植物僵尸

    import win32process#进程模块 import win32con#系统定义 import win32api#调用系统模块 import ctypes#C语言类型 import win3 ...

  3. 1.ArcGis几何图形之几何计算

    /// <summary> /// 检测几何图形A是否包含几何图形B /// </summary> /// <param name="pGeometryA&qu ...

  4. Android插件化原理解析——Hook机制之动态代理

    转自 http://weishu.me/2016/01/28/understand-plugin-framework-proxy-hook/ 使用代理机制进行API Hook进而达到方法增强是框架的常 ...

  5. Python 1:环境搭建及运行第一个程序

    在计算机控制面板中找到系统,然后点击高级系统设置,再点击环境变量,把安装的python.exe的目录复制到下面系统变量的path栏最后面,复制前加个分号以隔开前面的变量,然后按3次确定即可退出配置.具 ...

  6. java实现读取yaml文件,并获取值

    首先在项目src目录下新建一个test.yaml的文件. 代码如下: spring: application: name: cruncher datasource: driverClassName: ...

  7. 《CSS Mastery》 读书笔记 (1)

    --本笔记中英混合,专业名词尽量不翻译,免得误解,如果不习惯,就不用往下看了,走好不送. 第一章 基础 人类的好奇心总是促使我们捣鼓,捣鼓是最好做有效的学习CSS的方法 In this chapter ...

  8. (转)用JS实现表格中隔行显示不同颜色

    用JS实现表格中隔行显示不同颜色 第一种: <style> tr{bgColor:expression(     this.bgColor=((this.rowIndex)%2==0 )? ...

  9. Linux系统下通过命令行对mysql数据进行备份和还原

    一.备份 1.进入mysql目录 cd /var/lib/mysql (进入mysql目录,根据安装情况会有差别) 2.备份 mysqldump -u root -p密码 数据库名 数据表名 > ...

  10. 用一条mysql语句插入多条数据

    这篇文章主要介绍了在mysql中使用一条sql语句插入多条数据,效率非常高,但是原理其实很简单,希望对大家有所帮助 假如有一个数据表A: id name title addtime 如果需要插入n条数 ...