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. E20170815-mk

    frame  n. 框架; 边框; 眼镜框; 组织;

  2. 想要学好C/C++,我到底要看多少书才能成为一个合格的C/C++工程师?

    如何学好C语言 这可能是很多朋友的问题,我以前也有这样的感觉,编程编到一定的时候,发现能力到了瓶颈,既不深,也不扎实,半吊子.比如:你长期地使用Java和.NET ,这些有虚拟机的语言对于开发便利是便 ...

  3. POJ 1330 Tarjan LCA、ST表(其实可以数组模拟)

    题意:给你一棵树,求两个点的最近公共祖先. 思路:因为只有一组询问,直接数组模拟好了. (写得比较乱) 原题请戳这里 #include <cstdio> #include <bits ...

  4. C - Anton and Danik

    Problem description Anton likes to play chess, and so does his friend Danik. Once they have played n ...

  5. 在C#程序中,创建、写入、读取XML文件的方法

    一.在C#程序中,创建.写入.读取XML文件的方法 1.创建和读取XML文件的方法,Values为需要写入的值 private void WriteXML(string Values) { //保存的 ...

  6. 1C课程笔记分享_StudyJams_2017

    课程1C 概述 课程1C是创建一个生日贺卡应用的实践课程,所以本篇笔记分享主要记录个人的实践过程,此外分享一些比较零散的知识点. Drawable文件夹 Drawable文件夹是Android项目统一 ...

  7. mysql 导入数据库时,报错1840的解决方法

    1.现象 在mysql用sql文件导入数据库时,提示ERROR 1840 (HY000) at line 24: @@GLOBAL.GTID_PURGED can only be set when @ ...

  8. 【Linux】七种运行级别

    运行级别:即系统的运行模式. 级别类型: 0:关机状态. 1:单用户模式. 2:字符界面的多用户模式(不支持网络). 3:字符界面的多用户模式(运行最完整的模式). 4:未分配使用,系统保留. 5:图 ...

  9. C++编译错误fatal error C1004: 发现意外的文件尾

    出现这种情况就是类或者结构体的定义后面没有加“;”导致的. 而且这种问题好难排查.

  10. (转)openlayers实现在线编辑

    http://blog.csdn.net/gisshixisheng/article/details/46054949 概述: 在前面有篇博文讲述了基于Arcgis for js和wkt实现在线数据的 ...