Skip to content

Commit

Permalink
feat: angular 4 compatibility (#3608)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
crisbeto authored and jelbourn committed Mar 23, 2017
1 parent c524438 commit cd55082
Show file tree
Hide file tree
Showing 53 changed files with 370 additions and 264 deletions.
83 changes: 61 additions & 22 deletions guides/getting-started.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,55 @@
For help getting started with a new Angular app, check out the [Angular CLI](https://cli.angular.io/).
For help getting started with a new Angular app, check out the
[Angular CLI](https://cli.angular.io/).

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

## Step 1: Install Angular Material
## Step 1: Install Angular Material

```bash
npm install --save @angular/material
```

## Step 2: Import the Module

Add MaterialModule as an import in your app's root NgModule.

## Step 2: Animations

Some Material components depend on the Angular animations module in order to be able to do
more advanced transitions. If you want these animations to work in your app, you have to
install the `@angular/animations` module and include the `BrowserAnimationsModule` in your app.

```bash
npm install --save @angular/animations
```

```ts
import { MaterialModule } from '@angular/material';

import {BrowserAnimationsModule} from '@angular/platform-browser/animations';

@NgModule({
...
imports: [BrowserAnimationsModule],
...
})
export class PizzaPartyAppModule { }
```

If you don't want to add another dependency to your project, you can use the `NoopAnimationsModule`.

```ts
import {NoopAnimationsModule} from '@angular/platform-browser/animations';

@NgModule({
...
imports: [NoopAnimationsModule],
...
})
export class PizzaPartyAppModule { }
```

## Step 3: Import the Module

Add MaterialModule as an import in your app's root NgModule.

```ts
import {MaterialModule} from '@angular/material';

@NgModule({
...
imports: [MaterialModule],
Expand All @@ -23,9 +58,9 @@ import { MaterialModule } from '@angular/material';
export class PizzaPartyAppModule { }
```

## Step 3: Include Theming
## Step 4: Include Theming

Including a theme is **required** to apply all of the core and theme styles to your application.
Including a theme is **required** to apply all of the core and theme styles to your application.

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

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

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

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

## Step 4: Gesture Support
## Step 5: Gesture Support

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

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

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

## Step 5 (Optional): Add Material Icons
## Step 6 (Optional): Add Material Icons

If you want your `md-icon` components to use [Material Icons](https://material.io/icons/),
load the font in your `index.html`.

If you want your `md-icon` components to use [Material Icons](https://material.io/icons/), load the font in your `index.html`.

```html
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
```

For more information on using Material Icons, check out the [Material Icons Guide](https://google.github.io/material-design-icons/).
For more information on using Material Icons, check out the
[Material Icons Guide](https://google.github.io/material-design-icons/).

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

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


## Configuring SystemJS

If your project is using SystemJS for module loading, you will need to add `@angular/material`
If your project is using SystemJS for module loading, you will need to add `@angular/material`
to the SystemJS configuration:

```js
Expand Down
25 changes: 13 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,23 @@
"node": ">= 5.4.1 < 7"
},
"dependencies": {
"@angular/common": "^2.3.0",
"@angular/compiler": "^2.3.0",
"@angular/core": "^2.3.0",
"@angular/forms": "^2.3.0",
"@angular/http": "^2.3.0",
"@angular/platform-browser": "^2.3.0",
"@angular/animations": "^4.0.0-rc.5",
"@angular/common": "^4.0.0-rc.5",
"@angular/compiler": "^4.0.0-rc.5",
"@angular/core": "^4.0.0-rc.5",
"@angular/forms": "^4.0.0-rc.5",
"@angular/http": "^4.0.0-rc.5",
"@angular/platform-browser": "^4.0.0-rc.5",
"core-js": "^2.4.1",
"rxjs": "^5.0.1",
"systemjs": "0.19.43",
"zone.js": "^0.7.2"
"zone.js": "^0.8.4"
},
"devDependencies": {
"@angular/compiler-cli": "^2.3.0",
"@angular/platform-browser-dynamic": "^2.3.0",
"@angular/platform-server": "^2.3.0",
"@angular/router": "^3.3.0",
"@angular/compiler-cli": "^4.0.0-rc.5",
"@angular/platform-browser-dynamic": "^4.0.0-rc.5",
"@angular/platform-server": "^4.0.0-rc.5",
"@angular/router": "^4.0.0-rc.5",
"@types/chalk": "^0.4.31",
"@types/fs-extra": "0.0.37",
"@types/glob": "^5.0.30",
Expand Down Expand Up @@ -106,7 +107,7 @@
"ts-node": "^2.1.0",
"tslint": "^4.4.2",
"tslint-no-unused-var": "0.0.6",
"typescript": "~2.0.10",
"typescript": "~2.1.6",
"uglify-js": "^2.8.7",
"web-animations-js": "^2.2.2"
}
Expand Down
5 changes: 4 additions & 1 deletion src/demo-app/demo-app-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import {NgModule, ApplicationRef} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {HttpModule} from '@angular/http';
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
import {DemoApp, Home} from './demo-app/demo-app';
import {RouterModule} from '@angular/router';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
import {DemoApp, Home} from './demo-app/demo-app';
import {
MaterialModule,
OverlayContainer,
Expand Down Expand Up @@ -43,9 +44,11 @@ import {AutocompleteDemo} from './autocomplete/autocomplete-demo';
import {InputDemo} from './input/input-demo';
import {StyleDemo} from './style/style-demo';


@NgModule({
imports: [
BrowserModule,
BrowserAnimationsModule,
FormsModule,
HttpModule,
ReactiveFormsModule,
Expand Down
4 changes: 2 additions & 2 deletions src/demo-app/dialog/dialog-demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ <h2>Other options</h2>

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

<template>
<ng-template>
I'm a template dialog. I've been opened {{numTemplateOpens}} times!
</template>
</ng-template>
8 changes: 4 additions & 4 deletions src/demo-app/overlay/overlay-demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
Open menu
</button>

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

<!-- Template to load into an overlay. -->
<template cdk-portal>
<ng-template cdk-portal>
<p class="demo-fusilli"> Fusilli </p>
</template>
</ng-template>

<button (click)="openPanelWithBackdrop()">Backdrop panel</button>
8 changes: 4 additions & 4 deletions src/demo-app/portal/portal-demo.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h2> The portal host is here: </h2>
<div class="demo-portal-host">
<template [cdkPortalHost]="selectedPortal"></template>
<ng-template [cdkPortalHost]="selectedPortal"></ng-template>
</div>

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

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

<div *cdk-portal>
<p> - Did you hear about this year's Fibonacci Conference? </p>
Expand Down
4 changes: 4 additions & 0 deletions src/demo-app/system-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ System.config({
'@angular/http': 'vendor/@angular/http/bundles/http.umd.js',
'@angular/forms': 'vendor/@angular/forms/bundles/forms.umd.js',
'@angular/router': 'vendor/@angular/router/bundles/router.umd.js',
'@angular/animations': 'vendor/@angular/animations/bundles/animations.umd.js',
'@angular/animations/browser': 'vendor/@angular/animations/bundles/animations-browser.umd.js',
'@angular/platform-browser': 'vendor/@angular/platform-browser/bundles/platform-browser.umd.js',
'@angular/platform-browser/animations':
'vendor/@angular/platform-browser/bundles/platform-browser-animations.umd.js',
'@angular/platform-browser-dynamic':
'vendor/@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
'@angular/material': '@angular/material/bundles/material.umd.js'
Expand Down
10 changes: 5 additions & 5 deletions src/demo-app/tabs/tabs-demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ <h1>Tab Group Demo - Dynamic Tabs</h1>

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

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

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

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

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

<div class="tab-content">
{{tab.content}}
Expand Down
2 changes: 1 addition & 1 deletion src/e2e-app/dialog/dialog-e2e.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
<button id="disabled" (click)="openDisabled()">DISABLED</button>
<button id="template" (click)="openTemplate()">TEMPLATE</button>

<template><div class="my-template-dialog">my template dialog</div></template>
<ng-template><div class="my-template-dialog">my template dialog</div></ng-template>
5 changes: 3 additions & 2 deletions src/e2e-app/e2e-app-module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {NgModule} from '@angular/core';
import {BrowserModule, AnimationDriver} from '@angular/platform-browser';
import {BrowserModule} from '@angular/platform-browser';
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
import {RouterModule} from '@angular/router';
import {SimpleCheckboxes} from './checkbox/checkbox-e2e';
import {E2EApp, Home} from './e2e-app/e2e-app';
Expand All @@ -23,6 +24,7 @@ import {SlideToggleE2E} from './slide-toggle/slide-toggle-e2e';
BrowserModule,
RouterModule.forRoot(E2E_APP_ROUTES),
MaterialModule.forRoot(),
NoopAnimationsModule,
],
declarations: [
E2EApp,
Expand All @@ -45,7 +47,6 @@ import {SlideToggleE2E} from './slide-toggle/slide-toggle-e2e';
],
bootstrap: [E2EApp],
providers: [
{provide: AnimationDriver, useValue: AnimationDriver.NOOP},
{provide: OverlayContainer, useClass: FullscreenOverlayContainer}
],
entryComponents: [TestDialog, TestDialogFullScreen]
Expand Down
4 changes: 4 additions & 0 deletions src/e2e-app/system-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ System.config({
'@angular/http': 'vendor/@angular/http/bundles/http.umd.js',
'@angular/forms': 'vendor/@angular/forms/bundles/forms.umd.js',
'@angular/router': 'vendor/@angular/router/bundles/router.umd.js',
'@angular/animations': 'vendor/@angular/animations/bundles/animations.umd.js',
'@angular/animations/browser': 'vendor/@angular/animations/bundles/animations-browser.umd.js',
'@angular/platform-browser/animations':
'vendor/@angular/platform-browser/bundles/platform-browser-animations.umd.js',
'@angular/platform-browser': 'vendor/@angular/platform-browser/bundles/platform-browser.umd.js',
'@angular/platform-browser/testing':
'vendor/@angular/platform-browser/bundles/platform-browser-testing.umd.js',
Expand Down
6 changes: 3 additions & 3 deletions src/e2e-app/tabs/tabs-e2e.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<section>
<md-tab-group>
<md-tab>
<template md-tab-label>One</template>
<ng-template md-tab-label>One</ng-template>
First tab's content
</md-tab>
<md-tab>
<template md-tab-label>Two</template>
<ng-template md-tab-label>Two</ng-template>
Second tab's content
</md-tab>
<md-tab>
<template md-tab-label>Three</template>
<ng-template md-tab-label>Three</ng-template>
Third tab's content
</md-tab>
</md-tab-group>
Expand Down
4 changes: 2 additions & 2 deletions src/lib/autocomplete/autocomplete.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<ng-template>
<div class="mat-autocomplete-panel" role="listbox" [id]="id" [ngClass]="_getClassList()" #panel>
<ng-content></ng-content>
</div>
</template>
</ng-template>
Loading

0 comments on commit cd55082

Please sign in to comment.