Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions aio/content/examples/router/e2e/app.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,34 @@ describe('Router', () => {

function getPageStruct() {
const hrefEles = element.all(by.css('app-root > nav a'));
const crisisDetail = element.all(by.css('app-root > ng-component > ng-component > ng-component > div')).first();
const heroDetail = element(by.css('app-root > ng-component > div'));
const crisisDetail = element.all(by.css('app-root > div > ng-component > ng-component > ng-component > div')).first();
const heroDetail = element(by.css('app-root > div > ng-component'));

return {
hrefs: hrefEles,
activeHref: element(by.css('app-root > nav a.active')),

crisisHref: hrefEles.get(0),
crisisList: element.all(by.css('app-root > ng-component > ng-component li')),
crisisList: element.all(by.css('app-root > div > ng-component > ng-component li')),
crisisDetail: crisisDetail,
crisisDetailTitle: crisisDetail.element(by.xpath('*[1]')),

heroesHref: hrefEles.get(1),
heroesList: element.all(by.css('app-root > ng-component li')),
heroesList: element.all(by.css('app-root > div > ng-component li')),
heroDetail: heroDetail,
heroDetailTitle: heroDetail.element(by.xpath('*[1]')),
heroDetailTitle: heroDetail.element(by.xpath('*[2]')),

adminHref: hrefEles.get(2),
adminPreloadList: element.all(by.css('app-root > ng-component > ng-component > ul > li')),
adminPreloadList: element.all(by.css('app-root > div > ng-component > ng-component > ul > li')),

loginHref: hrefEles.get(3),
loginButton: element.all(by.css('app-root > ng-component > p > button')),
loginButton: element.all(by.css('app-root > div > ng-component > p > button')),

contactHref: hrefEles.get(4),
contactCancelButton: element.all(by.buttonText('Cancel')),

outletComponents: element.all(by.css('app-root > ng-component'))
primaryOutlet: element.all(by.css('app-root > div > ng-component')),
secondaryOutlet: element.all(by.css('app-root > ng-component'))
};
}

Expand Down Expand Up @@ -97,13 +98,15 @@ describe('Router', () => {
it('saves changed hero details', async () => {
const page = getPageStruct();
await page.heroesHref.click();
await browser.sleep(600);
const heroEle = page.heroesList.get(4);
let text = await heroEle.getText();
expect(text.length).toBeGreaterThan(0, 'hero item text length');
// remove leading id from text
const heroText = text.substr(text.indexOf(' ')).trim();

await heroEle.click();
await browser.sleep(600);
expect(page.heroesList.count()).toBe(0, 'hero list count');
expect(page.heroDetail.isPresent()).toBe(true, 'hero detail');
expect(page.heroDetailTitle.getText()).toContain(heroText);
Expand All @@ -113,6 +116,7 @@ describe('Router', () => {

let buttonEle = page.heroDetail.element(by.css('button'));
await buttonEle.click();
await browser.sleep(600);
expect(heroEle.getText()).toContain(heroText + '-foo');
});

Expand All @@ -129,7 +133,8 @@ describe('Router', () => {
const page = getPageStruct();
await page.heroesHref.click();
await page.contactHref.click();
expect(page.outletComponents.count()).toBe(2, 'route count');
expect(page.primaryOutlet.count()).toBe(1, 'primary outlet');
expect(page.secondaryOutlet.count()).toBe(1, 'secondary outlet');
});

async function crisisCenterEdit(index: number, save: boolean) {
Expand Down
51 changes: 30 additions & 21 deletions aio/content/examples/router/src/app/animations.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
// #docregion
import { animate, AnimationEntryMetadata, state, style, transition, trigger } from '@angular/core';
import {
trigger, animateChild, group,
transition, animate, style, query
} from '@angular/animations';

// Component transition animations
export const slideInDownAnimation: AnimationEntryMetadata =

// Routable animations
export const slideInAnimation =
trigger('routeAnimation', [
state('*',
style({
opacity: 1,
transform: 'translateX(0)'
})
),
transition(':enter', [
style({
opacity: 0,
transform: 'translateX(-100%)'
}),
animate('0.2s ease-in')
]),
transition(':leave', [
animate('0.5s ease-out', style({
opacity: 0,
transform: 'translateY(100%)'
}))
transition('heroes <=> hero', [
style({ position: 'relative' }),
query(':enter, :leave', [
style({
position: 'absolute',
top: 0,
left: 0,
width: '100%'
})
]),
query(':enter', [
style({ left: '-100%'})
]),
query(':leave', animateChild()),
group([
query(':leave', [
animate('300ms ease-out', style({ left: '100%'}))
]),
query(':enter', [
animate('300ms ease-out', style({ left: '0%'}))
])
]),
query(':enter', animateChild()),
])
]);
21 changes: 18 additions & 3 deletions aio/content/examples/router/src/app/app.component.2.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
/* Second Heroes version */
// #docregion
import { Component } from '@angular/core';
// #docregion animation-imports
import { RouterOutlet } from '@angular/router';
import { slideInAnimation } from './animations';
// #enddocregion animation-imports

@Component({
selector: 'app-root',
// #docregion template
template: `
<h1>Angular Router</h1>
<nav>
<a routerLink="/crisis-center" routerLinkActive="active">Crisis Center</a>
<a routerLink="/heroes" routerLinkActive="active">Heroes</a>
</nav>
<router-outlet></router-outlet>
`
<div [@routeAnimation]="getAnimationData(routerOutlet)">
<router-outlet #routerOutlet="outlet"></router-outlet>
</div>
`,
animations: [ slideInAnimation ]
// #enddocregion template
})
export class AppComponent { }
// #docregion function-binding
export class AppComponent {
getAnimationData(outlet: RouterOutlet) {
return outlet && outlet.activatedRouteData && outlet.activatedRouteData['animation'];
}
}
// #enddocregion function-binding
4 changes: 3 additions & 1 deletion aio/content/examples/router/src/app/app.component.4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import { Component } from '@angular/core';
// #enddocregion contact-link
</nav>
// #docregion outlets
<router-outlet></router-outlet>
<div [@routeAnimation]="getAnimationData(routerOutlet)">
<router-outlet #routerOutlet="outlet"></router-outlet>
</div>
<router-outlet name="popup"></router-outlet>
// #enddocregion outlets
`
Expand Down
4 changes: 3 additions & 1 deletion aio/content/examples/router/src/app/app.component.5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import { Component } from '@angular/core';
<a routerLink="/admin" routerLinkActive="active">Admin</a>
<a [routerLink]="[{ outlets: { popup: ['compose'] } }]">Contact</a>
</nav>
<router-outlet></router-outlet>
<div [@routeAnimation]="getAnimationData(routerOutlet)">
<router-outlet #routerOutlet="outlet"></router-outlet>
</div>
<router-outlet name="popup"></router-outlet>
`
// #enddocregion template
Expand Down
4 changes: 3 additions & 1 deletion aio/content/examples/router/src/app/app.component.6.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import { Component } from '@angular/core';
<a routerLink="/login" routerLinkActive="active">Login</a>
<a [routerLink]="[{ outlets: { popup: ['compose'] } }]">Contact</a>
</nav>
<router-outlet></router-outlet>
<div [@routeAnimation]="getAnimationData(routerOutlet)">
<router-outlet #routerOutlet="outlet"></router-outlet>
</div>
<router-outlet name="popup"></router-outlet>
`
// #enddocregion template
Expand Down
12 changes: 10 additions & 2 deletions aio/content/examples/router/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// #docplaster
// #docregion
import { Component } from '@angular/core';
import { RouterOutlet } from '@angular/router';
import { slideInAnimation } from './animations';

@Component({
selector: 'app-root',
Expand All @@ -14,10 +16,16 @@ import { Component } from '@angular/core';
<a routerLink="/login" routerLinkActive="active">Login</a>
<a [routerLink]="[{ outlets: { popup: ['compose'] } }]">Contact</a>
</nav>
<router-outlet></router-outlet>
<div [@routeAnimation]="getAnimationData(routerOutlet)">
<router-outlet #routerOutlet="outlet"></router-outlet>
</div>
<router-outlet name="popup"></router-outlet>
`
`,
animations: [ slideInAnimation ]
// #enddocregion template
})
export class AppComponent {
getAnimationData(outlet: RouterOutlet) {
return outlet && outlet.activatedRouteData && outlet.activatedRouteData['animation'];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,11 @@
import { Component, HostBinding } from '@angular/core';
import { Router } from '@angular/router';

import { slideInDownAnimation } from './animations';

@Component({
templateUrl: './compose-message.component.html',
styles: [ ':host { position: relative; bottom: 10%; }' ],
animations: [ slideInDownAnimation ]
styles: [ ':host { position: relative; bottom: 10%; }' ]
})
export class ComposeMessageComponent {
@HostBinding('@routeAnimation') routeAnimation = true;
@HostBinding('style.display') display = 'block';
@HostBinding('style.position') position = 'absolute';

details: string;
sending = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Component, OnInit, HostBinding } from '@angular/core';
import { ActivatedRoute, Router, ParamMap } from '@angular/router';
import { Observable } from 'rxjs/Observable';

import { slideInDownAnimation } from '../animations';
import { Crisis, CrisisService } from './crisis.service';
import { DialogService } from '../dialog.service';

Expand All @@ -25,14 +24,9 @@ import { DialogService } from '../dialog.service';
</p>
</div>
`,
styles: ['input {width: 20em}'],
animations: [ slideInDownAnimation ]
styles: ['input {width: 20em}']
})
export class CrisisDetailComponent implements OnInit {
@HostBinding('@routeAnimation') routeAnimation = true;
@HostBinding('style.display') display = 'block';
@HostBinding('style.position') position = 'absolute';

crisis: Crisis;
editName: string;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Component, OnInit, HostBinding } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { Observable } from 'rxjs/Observable';

import { slideInDownAnimation } from '../animations';
import { Crisis } from './crisis.service';
import { DialogService } from '../dialog.service';

Expand All @@ -24,14 +23,9 @@ import { DialogService } from '../dialog.service';
</p>
</div>
`,
styles: ['input {width: 20em}'],
animations: [ slideInDownAnimation ]
styles: ['input {width: 20em}']
})
export class CrisisDetailComponent implements OnInit {
@HostBinding('@routeAnimation') routeAnimation = true;
@HostBinding('style.display') display = 'block';
@HostBinding('style.position') position = 'absolute';

crisis: Crisis;
editName: string;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import { Component, OnInit, HostBinding } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { Router, ActivatedRoute, ParamMap } from '@angular/router';

import { slideInDownAnimation } from '../animations';

import { Hero, HeroService } from './hero.service';

@Component({
Expand All @@ -26,16 +24,9 @@ import { Hero, HeroService } from './hero.service';
<button (click)="gotoHeroes(hero)">Back</button>
</p>
</div>
`,
animations: [ slideInDownAnimation ]
`
})
export class HeroDetailComponent implements OnInit {
// #docregion host-bindings
@HostBinding('@routeAnimation') routeAnimation = true;
@HostBinding('style.display') display = 'block';
@HostBinding('style.position') position = 'absolute';
// #enddocregion host-bindings

hero$: Observable<Hero>;

// #docregion ctor
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// #docregion
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';

import { HeroListComponent } from './hero-list.component';
import { HeroDetailComponent } from './hero-detail.component';

const heroesRoutes: Routes = [
{ path: 'heroes', component: HeroListComponent, data: { animation: 'heroes' } },
{ path: 'hero/:id', component: HeroDetailComponent, data: { animation: 'hero' } }
];

@NgModule({
imports: [
RouterModule.forChild(heroesRoutes)
],
exports: [
RouterModule
]
})
export class HeroRoutingModule { }
// #enddocregion
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { HeroDetailComponent } from './hero-detail.component';
const heroesRoutes: Routes = [
{ path: 'heroes', redirectTo: '/superheroes' },
{ path: 'hero/:id', redirectTo: '/superhero/:id' },
{ path: 'superheroes', component: HeroListComponent },
{ path: 'superhero/:id', component: HeroDetailComponent }
{ path: 'superheroes', component: HeroListComponent, data: { animation: 'heroes' } },
{ path: 'superhero/:id', component: HeroDetailComponent, data: { animation: 'hero' } }
];

@NgModule({
Expand Down
Loading