Skip to content

Commit 9bd344a

Browse files
committed
chore(docs): add how-to's for angular material and angular material flex layout inclusion
applies to angular#2711
1 parent 39b9522 commit 9bd344a

File tree

1 file changed

+147
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)