Skip to content

Commit cd55082

Browse files
crisbetojelbourn
authored andcommitted
feat: angular 4 compatibility (#3608)
* Bumps the required Angular version to 4 and TypeScript to 2.1.6. * Fixes deprecation warnings for `<template>` usages. * Fixes any unit and e2e test failures. * Includes the new animations module and switches any components that use animations to it. * Fixes issues with the various test apps. Fixes #3357. Fixes #3336. FIxes #3301.
1 parent c524438 commit cd55082

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+370
-264
lines changed

guides/getting-started.md

Lines changed: 61 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,55 @@
1-
For help getting started with a new Angular app, check out the [Angular CLI](https://cli.angular.io/).
1+
For help getting started with a new Angular app, check out the
2+
[Angular CLI](https://cli.angular.io/).
23

34
For existing apps, follow these steps to begin using Angular Material.
45

5-
## Step 1: Install Angular Material
6+
## Step 1: Install Angular Material
67

78
```bash
89
npm install --save @angular/material
910
```
1011

11-
## Step 2: Import the Module
12-
13-
Add MaterialModule as an import in your app's root NgModule.
14-
12+
## Step 2: Animations
13+
14+
Some Material components depend on the Angular animations module in order to be able to do
15+
more advanced transitions. If you want these animations to work in your app, you have to
16+
install the `@angular/animations` module and include the `BrowserAnimationsModule` in your app.
17+
18+
```bash
19+
npm install --save @angular/animations
20+
```
21+
1522
```ts
16-
import { MaterialModule } from '@angular/material';
17-
23+
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
24+
25+
@NgModule({
26+
...
27+
imports: [BrowserAnimationsModule],
28+
...
29+
})
30+
export class PizzaPartyAppModule { }
31+
```
32+
33+
If you don't want to add another dependency to your project, you can use the `NoopAnimationsModule`.
34+
35+
```ts
36+
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
37+
38+
@NgModule({
39+
...
40+
imports: [NoopAnimationsModule],
41+
...
42+
})
43+
export class PizzaPartyAppModule { }
44+
```
45+
46+
## Step 3: Import the Module
47+
48+
Add MaterialModule as an import in your app's root NgModule.
49+
50+
```ts
51+
import {MaterialModule} from '@angular/material';
52+
1853
@NgModule({
1954
...
2055
imports: [MaterialModule],
@@ -23,9 +58,9 @@ import { MaterialModule } from '@angular/material';
2358
export class PizzaPartyAppModule { }
2459
```
2560

26-
## Step 3: Include Theming
61+
## Step 4: Include Theming
2762

28-
Including a theme is **required** to apply all of the core and theme styles to your application.
63+
Including a theme is **required** to apply all of the core and theme styles to your application.
2964

3065
To get started with a prebuilt theme, include the following in your app's index.html:
3166

@@ -35,16 +70,17 @@ To get started with a prebuilt theme, include the following in your app's index.
3570

3671
Note that your app's project structure may have a different relative location for your node_modules.
3772

38-
For more information on theming and instructions on how to create a custom theme, see the [theming guide](./theming.md).
73+
For more information on theming and instructions on how to create a custom theme, see the
74+
[theming guide](./theming.md).
3975

40-
## Step 4: Gesture Support
76+
## Step 5: Gesture Support
4177

42-
Some components (`md-slide-toggle`, `md-slider`, `mdTooltip`) rely on
78+
Some components (`md-slide-toggle`, `md-slider`, `mdTooltip`) rely on
4379
[HammerJS](http://hammerjs.github.io/) for gestures. In order to get the full feature-set of these
4480
components, HammerJS must be loaded into the application.
4581

46-
You can add HammerJS to your application via [npm](https://www.npmjs.com/package/hammerjs), a CDN
47-
(such as the [Google CDN](https://developers.google.com/speed/libraries/#hammerjs)), or served
82+
You can add HammerJS to your application via [npm](https://www.npmjs.com/package/hammerjs), a CDN
83+
(such as the [Google CDN](https://developers.google.com/speed/libraries/#hammerjs)), or served
4884
directly from your app.
4985

5086
To install via npm, use the following command:
@@ -57,22 +93,25 @@ After installing, import it on your app's root module.
5793
import 'hammerjs';
5894
```
5995

60-
## Step 5 (Optional): Add Material Icons
96+
## Step 6 (Optional): Add Material Icons
97+
98+
If you want your `md-icon` components to use [Material Icons](https://material.io/icons/),
99+
load the font in your `index.html`.
61100

62-
If you want your `md-icon` components to use [Material Icons](https://material.io/icons/), load the font in your `index.html`.
63-
64101
```html
65102
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
66103
```
67104

68-
For more information on using Material Icons, check out the [Material Icons Guide](https://google.github.io/material-design-icons/).
105+
For more information on using Material Icons, check out the
106+
[Material Icons Guide](https://google.github.io/material-design-icons/).
107+
108+
Note that `md-icon` has support for any font or svg icons, so using Material Icons is
109+
just one option.
69110

70-
Note that `md-icon` has support for any font or svg icons, so using Material Icons is just one option.
71-
72111

73112
## Configuring SystemJS
74113

75-
If your project is using SystemJS for module loading, you will need to add `@angular/material`
114+
If your project is using SystemJS for module loading, you will need to add `@angular/material`
76115
to the SystemJS configuration:
77116

78117
```js

package.json

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,23 @@
2525
"node": ">= 5.4.1 < 7"
2626
},
2727
"dependencies": {
28-
"@angular/common": "^2.3.0",
29-
"@angular/compiler": "^2.3.0",
30-
"@angular/core": "^2.3.0",
31-
"@angular/forms": "^2.3.0",
32-
"@angular/http": "^2.3.0",
33-
"@angular/platform-browser": "^2.3.0",
28+
"@angular/animations": "^4.0.0-rc.5",
29+
"@angular/common": "^4.0.0-rc.5",
30+
"@angular/compiler": "^4.0.0-rc.5",
31+
"@angular/core": "^4.0.0-rc.5",
32+
"@angular/forms": "^4.0.0-rc.5",
33+
"@angular/http": "^4.0.0-rc.5",
34+
"@angular/platform-browser": "^4.0.0-rc.5",
3435
"core-js": "^2.4.1",
3536
"rxjs": "^5.0.1",
3637
"systemjs": "0.19.43",
37-
"zone.js": "^0.7.2"
38+
"zone.js": "^0.8.4"
3839
},
3940
"devDependencies": {
40-
"@angular/compiler-cli": "^2.3.0",
41-
"@angular/platform-browser-dynamic": "^2.3.0",
42-
"@angular/platform-server": "^2.3.0",
43-
"@angular/router": "^3.3.0",
41+
"@angular/compiler-cli": "^4.0.0-rc.5",
42+
"@angular/platform-browser-dynamic": "^4.0.0-rc.5",
43+
"@angular/platform-server": "^4.0.0-rc.5",
44+
"@angular/router": "^4.0.0-rc.5",
4445
"@types/chalk": "^0.4.31",
4546
"@types/fs-extra": "0.0.37",
4647
"@types/glob": "^5.0.30",
@@ -106,7 +107,7 @@
106107
"ts-node": "^2.1.0",
107108
"tslint": "^4.4.2",
108109
"tslint-no-unused-var": "0.0.6",
109-
"typescript": "~2.0.10",
110+
"typescript": "~2.1.6",
110111
"uglify-js": "^2.8.7",
111112
"web-animations-js": "^2.2.2"
112113
}

src/demo-app/demo-app-module.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import {NgModule, ApplicationRef} from '@angular/core';
22
import {BrowserModule} from '@angular/platform-browser';
33
import {HttpModule} from '@angular/http';
44
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
5-
import {DemoApp, Home} from './demo-app/demo-app';
65
import {RouterModule} from '@angular/router';
6+
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
7+
import {DemoApp, Home} from './demo-app/demo-app';
78
import {
89
MaterialModule,
910
OverlayContainer,
@@ -43,9 +44,11 @@ import {AutocompleteDemo} from './autocomplete/autocomplete-demo';
4344
import {InputDemo} from './input/input-demo';
4445
import {StyleDemo} from './style/style-demo';
4546

47+
4648
@NgModule({
4749
imports: [
4850
BrowserModule,
51+
BrowserAnimationsModule,
4952
FormsModule,
5053
HttpModule,
5154
ReactiveFormsModule,

src/demo-app/dialog/dialog-demo.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,6 @@ <h2>Other options</h2>
6767

6868
<p>Last close result: {{lastCloseResult}}</p>
6969

70-
<template>
70+
<ng-template>
7171
I'm a template dialog. I've been opened {{numTemplateOpens}} times!
72-
</template>
72+
</ng-template>

src/demo-app/overlay/overlay-demo.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@
1515
Open menu
1616
</button>
1717

18-
<template cdk-connected-overlay [origin]="trigger" [width]="500" hasBackdrop [open]="isMenuOpen"
18+
<ng-template cdk-connected-overlay [origin]="trigger" [width]="500" hasBackdrop [open]="isMenuOpen"
1919
(backdropClick)="isMenuOpen=false">
2020
<div style="background-color: mediumpurple" >
2121
This is the menu panel.
2222
</div>
23-
</template>
23+
</ng-template>
2424

2525
<!-- Template to load into an overlay. -->
26-
<template cdk-portal>
26+
<ng-template cdk-portal>
2727
<p class="demo-fusilli"> Fusilli </p>
28-
</template>
28+
</ng-template>
2929

3030
<button (click)="openPanelWithBackdrop()">Backdrop panel</button>

src/demo-app/portal/portal-demo.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<h2> The portal host is here: </h2>
22
<div class="demo-portal-host">
3-
<template [cdkPortalHost]="selectedPortal"></template>
3+
<ng-template [cdkPortalHost]="selectedPortal"></ng-template>
44
</div>
55

66
<button type="button" (click)="selectedPortal = programmingJoke">
@@ -15,15 +15,15 @@ <h2> The portal host is here: </h2>
1515
Science joke
1616
</button>
1717

18-
<!-- Template vars on <template> elements can't be accessed _in_ the template because Angular
18+
<!-- Template vars on <ng-template> elements can't be accessed _in_ the template because Angular
1919
doesn't support grabbing the instance / TemplateRef this way because the variable may be
2020
referring to something *in* the template (such as #item in ngFor). As such, the component
2121
has to use @ViewChild / @ViewChildren to get these references.
2222
See https://github.com/angular/angular/issues/7158 -->
23-
<template cdk-portal>
23+
<ng-template cdk-portal>
2424
<p> - Why don't jokes work in octal?</p>
2525
<p> - Because 7 10 11.</p>
26-
</template>
26+
</ng-template>
2727

2828
<div *cdk-portal>
2929
<p> - Did you hear about this year's Fibonacci Conference? </p>

src/demo-app/system-config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ System.config({
1414
'@angular/http': 'vendor/@angular/http/bundles/http.umd.js',
1515
'@angular/forms': 'vendor/@angular/forms/bundles/forms.umd.js',
1616
'@angular/router': 'vendor/@angular/router/bundles/router.umd.js',
17+
'@angular/animations': 'vendor/@angular/animations/bundles/animations.umd.js',
18+
'@angular/animations/browser': 'vendor/@angular/animations/bundles/animations-browser.umd.js',
1719
'@angular/platform-browser': 'vendor/@angular/platform-browser/bundles/platform-browser.umd.js',
20+
'@angular/platform-browser/animations':
21+
'vendor/@angular/platform-browser/bundles/platform-browser-animations.umd.js',
1822
'@angular/platform-browser-dynamic':
1923
'vendor/@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
2024
'@angular/material': '@angular/material/bundles/material.umd.js'

src/demo-app/tabs/tabs-demo.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ <h1>Tab Group Demo - Dynamic Tabs</h1>
4848

4949
<md-tab-group class="demo-tab-group" dynamicHeight [(selectedIndex)]="activeTabIndex">
5050
<md-tab *ngFor="let tab of dynamicTabs" [disabled]="tab.disabled">
51-
<template md-tab-label>{{tab.label}}</template>
51+
<ng-template md-tab-label>{{tab.label}}</ng-template>
5252
<div class="tab-content">
5353
{{tab.content}}
5454
<br>
@@ -100,7 +100,7 @@ <h1>Tab Group Demo - Dynamic Height</h1>
100100

101101
<md-tab-group class="demo-tab-group" dynamicHeight>
102102
<md-tab *ngFor="let tab of tabs" [disabled]="tab.disabled">
103-
<template md-tab-label>{{tab.label}}</template>
103+
<ng-template md-tab-label>{{tab.label}}</ng-template>
104104
<div class="tab-content">
105105
{{tab.content}}
106106
<br>
@@ -146,7 +146,7 @@ <h1>Tab Group Demo - Fixed Height</h1>
146146

147147
<md-tab-group class="demo-tab-group" style="height: 220px">
148148
<md-tab *ngFor="let tab of tabs" [disabled]="tab.disabled">
149-
<template md-tab-label>{{tab.label}}</template>
149+
<ng-template md-tab-label>{{tab.label}}</ng-template>
150150
<div class="tab-content">
151151
{{tab.content}}
152152
<br>
@@ -191,7 +191,7 @@ <h1>Stretched Tabs</h1>
191191

192192
<md-tab-group class="demo-tab-group" style="height: 200px" md-stretch-tabs>
193193
<md-tab *ngFor="let tab of tabs" [disabled]="tab.disabled">
194-
<template md-tab-label>{{tab.label}}</template>
194+
<ng-template md-tab-label>{{tab.label}}</ng-template>
195195
<div class="tab-content">
196196
{{tab.content}}
197197
</div>
@@ -203,7 +203,7 @@ <h1>Async Tabs</h1>
203203

204204
<md-tab-group class="demo-tab-group">
205205
<md-tab *ngFor="let tab of asyncTabs | async; let i = index" [disabled]="i == 1">
206-
<template md-tab-label>{{tab.label}}</template>
206+
<ng-template md-tab-label>{{tab.label}}</ng-template>
207207

208208
<div class="tab-content">
209209
{{tab.content}}

src/e2e-app/dialog/dialog-e2e.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
<button id="disabled" (click)="openDisabled()">DISABLED</button>
33
<button id="template" (click)="openTemplate()">TEMPLATE</button>
44

5-
<template><div class="my-template-dialog">my template dialog</div></template>
5+
<ng-template><div class="my-template-dialog">my template dialog</div></ng-template>

src/e2e-app/e2e-app-module.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {NgModule} from '@angular/core';
2-
import {BrowserModule, AnimationDriver} from '@angular/platform-browser';
2+
import {BrowserModule} from '@angular/platform-browser';
3+
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
34
import {RouterModule} from '@angular/router';
45
import {SimpleCheckboxes} from './checkbox/checkbox-e2e';
56
import {E2EApp, Home} from './e2e-app/e2e-app';
@@ -23,6 +24,7 @@ import {SlideToggleE2E} from './slide-toggle/slide-toggle-e2e';
2324
BrowserModule,
2425
RouterModule.forRoot(E2E_APP_ROUTES),
2526
MaterialModule.forRoot(),
27+
NoopAnimationsModule,
2628
],
2729
declarations: [
2830
E2EApp,
@@ -45,7 +47,6 @@ import {SlideToggleE2E} from './slide-toggle/slide-toggle-e2e';
4547
],
4648
bootstrap: [E2EApp],
4749
providers: [
48-
{provide: AnimationDriver, useValue: AnimationDriver.NOOP},
4950
{provide: OverlayContainer, useClass: FullscreenOverlayContainer}
5051
],
5152
entryComponents: [TestDialog, TestDialogFullScreen]

src/e2e-app/system-config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ System.config({
1414
'@angular/http': 'vendor/@angular/http/bundles/http.umd.js',
1515
'@angular/forms': 'vendor/@angular/forms/bundles/forms.umd.js',
1616
'@angular/router': 'vendor/@angular/router/bundles/router.umd.js',
17+
'@angular/animations': 'vendor/@angular/animations/bundles/animations.umd.js',
18+
'@angular/animations/browser': 'vendor/@angular/animations/bundles/animations-browser.umd.js',
19+
'@angular/platform-browser/animations':
20+
'vendor/@angular/platform-browser/bundles/platform-browser-animations.umd.js',
1721
'@angular/platform-browser': 'vendor/@angular/platform-browser/bundles/platform-browser.umd.js',
1822
'@angular/platform-browser/testing':
1923
'vendor/@angular/platform-browser/bundles/platform-browser-testing.umd.js',

src/e2e-app/tabs/tabs-e2e.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<section>
22
<md-tab-group>
33
<md-tab>
4-
<template md-tab-label>One</template>
4+
<ng-template md-tab-label>One</ng-template>
55
First tab's content
66
</md-tab>
77
<md-tab>
8-
<template md-tab-label>Two</template>
8+
<ng-template md-tab-label>Two</ng-template>
99
Second tab's content
1010
</md-tab>
1111
<md-tab>
12-
<template md-tab-label>Three</template>
12+
<ng-template md-tab-label>Three</ng-template>
1313
Third tab's content
1414
</md-tab>
1515
</md-tab-group>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
<template>
1+
<ng-template>
22
<div class="mat-autocomplete-panel" role="listbox" [id]="id" [ngClass]="_getClassList()" #panel>
33
<ng-content></ng-content>
44
</div>
5-
</template>
5+
</ng-template>

0 commit comments

Comments
 (0)