Skip to content

Commit 2394c18

Browse files
authored
docs: update guides and public APIs for NgModules (#961)
* docs: update guides and public APIs for NgModules * fix bad import * fix typo * clarify @types and remove redundant setup
1 parent 2bfbd58 commit 2394c18

File tree

24 files changed

+61
-104
lines changed

24 files changed

+61
-104
lines changed

GETTING_STARTED.md

Lines changed: 24 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ some initial config for the SystemJS module loader.
2121
### Install Angular Material 2 components
2222

2323
Now that your project has been created, you can install any Angular Material 2 components you'd like
24-
to use through npm. You can see our [list of published packages here](https://www.npmjs.com/~angular2-material).
24+
to use through npm. You can see our [list of published packages here](https://www.npmjs.com/~angular2-material).
25+
26+
Note that only packages published under the `@latest` npm tag are officially released.
2527

2628
```bash
2729
npm install --save @angular2-material/core @angular2-material/button @angular2-material/card
2830
```
29-
Note: the core module is required as a peer dependency of other components.
31+
(the core module is required as a peer dependency of other components)
3032

3133
### Add components to vendor bundle
3234

@@ -98,96 +100,43 @@ Now you should be able to import the components normally wherever you'd like to
98100

99101
**src/app/my-project.component.ts**
100102
```ts
101-
import { MD_CARD_DIRECTIVES } from '@angular2-material/card';
102-
import { MD_BUTTON_DIRECTIVES } from '@angular2-material/button';
103+
import { MdCardModule } from '@angular2-material/card';
104+
import { MdButtonModule } from '@angular2-material/button';
103105
```
104106

105-
And don't forget to add the directives to your directives array:
107+
Import the components in your application module:
106108

107-
**src/app/my-project.component.ts**
109+
**my-app-module.ts**
108110
```ts
109-
directives: [MD_CARD_DIRECTIVES, MD_BUTTON_DIRECTIVES]
111+
@NgModule({
112+
imports: [MdButtonModule, MdCardModule],
113+
...
114+
})
110115
```
111116

112117
### Sample Angular Material 2 projects
113118

114-
- [Puppy Love (ng-conf 2016)](https://github.com/kara/puppy-love) - see live demo [here](https://youtu.be/rRiV_b3WsoY?t=4m20s)
115-
- [Puppy Love Mobile (Google IO 2016)](https://github.com/kara/puppy-love-io)
116119
- [Material 2 Sample App](https://github.com/jelbourn/material2-app)
117120

118-
### Additional steps for using Material components with forms
119-
120-
If you're using Angular Material 2 version alpha.6 or later, you'll need to upgrade to Angular 2's
121-
new forms module. Here's how:
122-
123-
- Install the `@angular/forms` package. If you're on Angular RC.4, install version 0.2.0.
124-
125-
```bash
126-
npm install @angular/forms
127-
```
128-
129-
- Change your bootstrap file to disable the old form directives and provide the new form
130-
directives.
131-
132-
**main.ts**
133-
```ts
134-
import {disableDeprecatedForms, provideForms} from '@angular/forms';
121+
(the following are slightly out of date now)
122+
- [Puppy Love (ng-conf 2016)](https://github.com/kara/puppy-love) - see live demo [here](https://youtu.be/rRiV_b3WsoY?t=4m20s)
123+
- [Puppy Love Mobile (Google IO 2016)](https://github.com/kara/puppy-love-io)
135124

136-
bootstrap(MyAppComponent, [
137-
disableDeprecatedForms(),
138-
provideForms()
139-
]);
140-
```
141125

142-
- Import any and all forms symbols - `NgForm`, `Validators`, etc - from `@angular/forms`.
143-
Importing them from `@angular/common` will result in a `No value accessor found` error.
126+
### Additional setup for `md-slide-toggle` and `md-slider`:
127+
The slide-toggle and slider components have a dependency on [HammerJS](http://hammerjs.github.io/).
128+
1) Add HammerJS to your application via [npm](https://www.npmjs.com/package/hammerjs), a CDN
129+
(such as the [Google CDN](https://developers.google.com/speed/libraries/#hammerjs)),
130+
or served directly from your app.
131+
2) Include the typings for HammerJS in your typescript build ([more info on @types](https://blogs.msdn.microsoft.com/typescript/2016/06/15/the-future-of-declaration-files))
144132

145-
- Update your form code to use the new APIs. See more information about the changes in the proposal
146-
doc [here](https://docs.google.com/document/u/1/d/1RIezQqE4aEhBRmArIAS1mRIZtWFf6JxN_7B4meyWK0Y/pub)
147-
and the official documentation [here](https://angular.io/docs/ts/latest/guide/forms.html).
148133

149-
### Additional steps for `md-icon` setup:
134+
### Additional setup for `md-icon`:
150135

151-
- If you want to use Material Design icons, load the Material Design font in your `index.html`. `md-icon` supports any font icons or svg icons,
152-
so this is only one potential option.
136+
- If you want to use Material Design icons, load the Material Design font in your `index.html`.
137+
`md-icon` supports any font icons or svg icons, so this is only one potential option.
153138

154139
**src/index.html**
155140
```html
156141
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
157142
```
158-
159-
- Include http providers in your `main.ts`:
160-
161-
**src/main.ts**
162-
```ts
163-
import { HTTP_PROVIDERS } from '@angular/http';
164-
...
165-
bootstrap(MyAppComponent, [
166-
HTTP_PROVIDERS
167-
]);
168-
```
169-
170-
- Provide the icon registry at or above the component where you're using the icon:
171-
172-
**src/app/my-project.component.ts**
173-
```ts
174-
import {MdIcon, MdIconRegistry} from '@angular2-material/icon';
175-
...
176-
directives: [MD_CARD_DIRECTIVES, MD_BUTTON_DIRECTIVES, MdIcon],
177-
providers: [MdIconRegistry]
178-
```
179-
180-
- Add the icon package to the list of Material components in your `system-config.ts`:
181-
182-
**src/system-config.ts**
183-
```ts
184-
// put the names of any of your Material components here
185-
const materialPkgs:string[] = [
186-
...
187-
'icon'
188-
];
189-
```
190-
191-
192-
193-

src/components/button-toggle/button-toggle.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ export class MdButtonToggle implements OnInit {
383383
}
384384
}
385385

386+
/** @deprecated */
386387
export const MD_BUTTON_TOGGLE_DIRECTIVES = [
387388
MdButtonToggleGroup,
388389
MdButtonToggleGroupMultiple,

src/components/button/button.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
} from '@angular/core';
1212
import {CommonModule} from '@angular/common';
1313
import {BooleanFieldValue} from '@angular2-material/core/annotations/field-value';
14-
import {MdRippleModule} from '../../core/ripple/ripple';
14+
import {MdRippleModule} from '@angular2-material/core/ripple/ripple';
1515

1616
// TODO(jelbourn): Make the `isMouseDown` stuff done with one global listener.
1717
// TODO(kara): Convert attribute selectors to classes when attr maps become available
@@ -157,6 +157,7 @@ export class MdAnchor extends MdButton {
157157
}
158158

159159

160+
/** @deprecated */
160161
export const MD_BUTTON_DIRECTIVES: Type[] = [MdButton, MdAnchor];
161162

162163

src/components/card/card.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ TODO(kara): update link to demo site when it exists
7474
})
7575
export class MdCardTitleGroup {}
7676

77+
/** @deprecated */
7778
export const MD_CARD_DIRECTIVES: any[] = [MdCard, MdCardHeader, MdCardTitleGroup];
7879

7980

src/components/checkbox/checkbox.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ export class MdCheckbox implements ControlValueAccessor {
304304
}
305305
}
306306

307+
/** @deprecated */
307308
export const MD_CHECKBOX_DIRECTIVES = [MdCheckbox];
308309

309310

src/components/grid-list/grid-list.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ export class MdGridList implements OnInit, AfterContentChecked {
152152
}
153153

154154

155+
/** @deprecated */
155156
export const MD_GRID_LIST_DIRECTIVES: any[] = [MdGridList, MdGridTile, MdGridTileText];
156157

157158

src/components/icon/icon.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ export class MdIcon implements OnChanges, OnInit, AfterViewChecked {
225225
}
226226
}
227227

228+
/** @deprecated */
228229
export const MD_ICON_DIRECTIVES = [MdIcon];
229230

230231

src/components/input/input.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ export class MdInput implements ControlValueAccessor, AfterContentInit, OnChange
307307
}
308308
}
309309

310+
/** @deprecated */
310311
export const MD_INPUT_DIRECTIVES = [MdPlaceholder, MdInput, MdHint];
311312

312313

src/components/list/list.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export class MdListItem implements AfterContentInit {
6565
}
6666
}
6767

68+
/** @deprecated */
6869
export const MD_LIST_DIRECTIVES = [MdList, MdListItem, MdListAvatar];
6970

7071

src/components/menu/README.md

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,17 @@
1414

1515
### Setup
1616

17-
`md-menu` relies on the existence of an app-wide `OverlayContainer`. This is the container in which
18-
it will display. You'll need to import this from `@angular2-material/core` and add it to your
19-
providers list on bootstrap.
17+
Import the MdMenu module.
2018

21-
*main.ts*
19+
*my-app-module.ts*
2220
```ts
23-
import { OverlayContainer } from '@angular2-material/core';
21+
import {MdMenuModule} from '@angular2-material/menu';
2422

25-
bootstrap(AppComponent, [
26-
OverlayContainer
27-
]);
28-
```
29-
30-
You'll also want to import the menu directives and add them to your component's directives array:
31-
32-
*my-comp.component.ts*
33-
```ts
34-
import {MD_MENU_DIRECTIVES} from '@angular2-material/menu';
35-
36-
@Component({
23+
@NgModule({
24+
imports: [MdMenuModule],
3725
...
38-
directives: [MD_MENU_DIRECTIVES]
3926
})
40-
class MyComp {}
27+
export class MyAppModule {}
4128
```
4229

4330
### Simple menu

0 commit comments

Comments
 (0)