[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 ...
随机推荐
- 1tb等于多少g 1TB和500G有什么区别
转自:http://www.a207.com/article/view_39392 移动硬盘.U盘是生活中常见的用品,他们的内存大小是什么标准.很多人对于1tb等于多少g和1tb和500g有什么区别不 ...
- hdu1429胜利大逃亡(bfs)
胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
- HttpClient短信接口
HttpClient简介 HTTP 协议可能是现在 Internet 上使用得最多.最重要的协议了,越来越多的 Java 应用程序需要直接通过 HTTP 协议来访问网络资源.虽然在 JDK 的 jav ...
- MySQL Connector for .NET 和 EF版本匹配问题
以下讨论的都是EF5.0, 版本号:4.4.0.0 如果装了MySQL 5.0.1 , 那么最好用MySQL Connector 6.3.6,但是创建数据库后,生成迁移历史表的时候,会报错,你不管,直 ...
- 数据库 'tempdb' 的事务日志已满。若要查明无法重用日志中的空间的原因
最常的做法: --1.清空日志 DUMP TRANSACTION tempdb WITH NO_LOG --2.截断事务日志: BACKUP LOG tempdb WITH NO_LOG --3.收缩 ...
- 阶乘问题-----sum随变量改变而改变
- 【PostgreSQL-9.6.3】如何得到psql中命令的实际执行SQL
当我们在psql界面执行以“\”开头的命令时,数据库会立刻返回执行结果,而不会返回命令的实际执行过程.通过两种方式可以实现执行过程的查看: 方法一:启动psql命令时加“-E”参数 postgres@ ...
- Linux while和for循环简单分析
一.循环重定向 最近遇到了一种新的循环重定向写法,由于没看懂,说以网上搜索了一下,然后再此分享一下: while read line do ...... done < file 刚开始看,不明 ...
- texi格式文件的读取
使用texi2html可以将texi格式的文件转换成html格式的文件. sudo apt-get install texi2html 在对应目录下 texi2html filename.texi 或 ...
- git解决内容冲突
内容冲突的冲突处理 两个用户修改了同一个文件的同一块区域,git会报告内容冲突. 解决办法:打开发生冲突的文件,会发现 <<<<<<< HEADtest in ...