Skip to content

Commit 3464ee7

Browse files
committed
chore(docs): add how-to's for angular material and angular material flex layout inclusion
applies to angular#2711
1 parent 338e69b commit 3464ee7

File tree

1 file changed

+148
-0
lines changed

1 file changed

+148
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
# Include [Angular Material](https://material.angular.io)
2+
3+
[Angular Material](https://material.angular.io) is a set of Material Design components for Angular apps.
4+
This guide will walk you through adding material design to your Angular CLI project and configuring it to use Angular Material.
5+
6+
Create a new project and navigate into the project...
7+
```
8+
ng new my-app && cd my-app
9+
```
10+
11+
With the new project created and ready, you will next need to install Angular Material.
12+
13+
Install the `@angular/material` library and add the dependency to package.json...
14+
```bash
15+
npm install --save @angular/material
16+
17+
```
18+
19+
Import the Angular Material NgModule into your app module...
20+
```javascript
21+
//in src/app/app.module.ts -->
22+
23+
import { MaterialModule } from '@angular/material';
24+
// other imports
25+
26+
@NgModule({
27+
imports: [
28+
...
29+
MaterialModule.forRoot()
30+
],
31+
...
32+
})
33+
34+
```
35+
36+
Now that the project is set up, it must be configured to include the CSS for a theme. Angular Material ships with some prebuilt theming, which is located in `node_modules/@angular/material/core/theming/prebuilt`.
37+
38+
To add an angular CSS theme and material icons to your app...
39+
```css
40+
/* in src/styles.css */
41+
42+
@import '~@angular/material/core/theming/prebuilt/deeppurple-amber.css';
43+
@import '~https://fonts.googleapis.com/icon?family=Material+Icons';
44+
```
45+
46+
Run `ng serve` to run your application in develop mode, and navigate to `http://localhost:4200`.
47+
48+
To verify angular material has been set up correctly, change `src/app/app.component.html` to the following...
49+
```html
50+
<h1>
51+
{{title}}
52+
</h1>
53+
54+
<button md-raised-button>
55+
angular material works!
56+
<md-icon>done</md-icon>
57+
</button>
58+
```
59+
60+
After saving this file, return to the browser to see the angular material styled button.
61+
62+
### Guides
63+
64+
- [Getting Started](https://material.angular.io/guide/getting-started)
65+
- [Theming Angular Material](https://material.angular.io/guide/theming)
66+
- [Theming your own components](https://material.angular.io/guide/theming-your-components)
67+
68+
# Include [Flex Layout](https://github.com/angular/flex-layout) for [Angular Material](https://material.angular.io)
69+
70+
Include Angular Material as detailed above.
71+
72+
Install the `@angular/flex-layout` library and add the dependency to package.json...
73+
```bash
74+
npm install --save @angular/flex-layout
75+
76+
```
77+
78+
Import the Angular Flex-Layout NgModule into your app module...
79+
```javascript
80+
//in src/app/app.module.ts -->
81+
82+
import { FlexLayoutModule } from '@angular/flex-layout';
83+
// other imports
84+
85+
@NgModule({
86+
imports: [
87+
...
88+
FlexLayoutModule.forRoot()
89+
],
90+
...
91+
})
92+
93+
```
94+
95+
Run `ng serve` to run your application in develop mode, and navigate to `http://localhost:4200`
96+
97+
Add the following to `src/app/app.component.css`...
98+
```css
99+
.header {
100+
background-color: lightyellow;
101+
}
102+
103+
.left {
104+
background-color: lightblue;
105+
}
106+
107+
.right {
108+
background-color: pink;
109+
}
110+
```
111+
112+
To verify flex-layout has been set up correctly, change `src/app/app.component.html` to the following...
113+
```html
114+
<div fxLayout="column">
115+
116+
<div class="header" fxLayout="row" fxLayoutAlign="space-between center">
117+
118+
<h1>
119+
{{title}}
120+
</h1>
121+
122+
<button md-raised-button>
123+
angular material works!
124+
<md-icon>done</md-icon>
125+
</button>
126+
127+
</div>
128+
129+
<div fxLayout="row">
130+
131+
<div class="left" fxFlex="20">
132+
LEFT: 20% wide
133+
</div>
134+
135+
<div class="right" fxFlex>
136+
RIGHT: 80% wide
137+
</div>
138+
139+
</div>
140+
</div>
141+
142+
```
143+
144+
After saving this file, return to the browser to see the very ugly but demonstrative flex-layout.
145+
146+
Among what you should see are - a light yellow header that is the entire width of the window, sitting directly atop 2 columns. Of those 2 columns, the left column should be light blue, and 20% wide, while the right column is pink, 80% to start, and will flex with window (re)size.
147+
148+

0 commit comments

Comments
 (0)