[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 ...
随机推荐
- Python入门 老司机带你上路
Phthon安装 https://www.python.org/download/releases/2.7.5/ 安装结束还没完,我们还差最后一步:设置环境变量.这是什么东西我暂时先不解释,大家照着做 ...
- PCB Genesis 鼠标滚轮缩放与TGZ拖放 插件实现
一.背景: 做过CAM的人都用过Geneiss软件,由于处理资料强大,目前奥宝公司出品的Genesis占领整个PCB行业,整个行业无人不知呀, 而此软件有一个吐槽点Genesis 无滚轮缩放与TGZ拖 ...
- 原生JS---8
原生js学习笔记8——Ajax基础 什么是Ajax 不刷新页面的情况下从服务器获取.提交数据的一种数据交互方式. Ajax使用步骤 1.创建Ajax对象 var httpRequest = new ...
- 关于Vue.js去掉#号路由
正常启动后访问路由: 中间会自动加入一个#号 去掉#号: 在route文件夹下的index.js中加入mode: 'history', ①: ②: 关于mode说明: 默认值: ‘hash‘(浏览器) ...
- 练习2 及pl/sql
Rownum 如果不是对主键排序是不会变得 -查询没有学分的学生信息 --SELECT * FROM z_student zs WHERE zs.code NOT IN (SELECT DISTINC ...
- ACM_小明滚出去?(求逆序数)
小明滚出去? Time Limit: 2000/1000ms (Java/Others) Problem Description: 老师:“小明,写一个排序算法”: 小明: void mysort(i ...
- C#之仿魔兽登录
不多废话,直接上效果图: 1录窗体 对应的代码: using System; using System.Collections.Generic; using System.ComponentModel ...
- 关于EasyUI datagrid editor combogrid搜索框的实现
首先需要datagrid editor对combogrid的扩展,这个是别人实现的: $.extend($.fn.datagrid.defaults.editors, { combogrid: { i ...
- SQLServer In和Exists
In Exists () 1分42秒 5秒 Exists() 返回布尔值 如果子查询结果行>0,则返回 TRUE. 反之返回FALSE exists(select * fro ...
- for 循环 乘法口诀表
用for循环写乘法口诀表: for(var i = 1; i <= 9; i++) { var c=''; for(var x = 1; x <= i; x++) { c=c+x+' ...