Skip to content

Commit daa35dd

Browse files
test(integration): Wire up ui-router example
1 parent 47dc09d commit daa35dd

File tree

11 files changed

+214
-59
lines changed

11 files changed

+214
-59
lines changed

test/integration/angularV5/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"@angular/platform-browser": "^5.0.0",
2222
"@angular/platform-browser-dynamic": "^5.0.0",
2323
"@angular/router": "^5.0.0",
24+
"@uirouter/angular": "^1.1.0",
2425
"core-js": "^2.4.1",
2526
"rxjs": "^5.5.2",
2627
"zone.js": "^0.8.14"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { Component } from '@angular/core';
2+
3+
@Component({
4+
selector: 'app-about',
5+
template: `<p>about works!</p>`,
6+
})
7+
export class AboutComponent {}

test/integration/angularV5/src/app/app.component.css

Whitespace-only changes.

test/integration/angularV5/src/app/app.component.html

Lines changed: 0 additions & 20 deletions
This file was deleted.

test/integration/angularV5/src/app/app.component.spec.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,40 @@
11
import { Component } from '@angular/core';
22

3+
const template = `
4+
<ui-view name="header" id="header"></ui-view>
5+
6+
<div class="app">
7+
<img width="300" alt="Angular Logo" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNTAgMjUwIj4KICAgIDxwYXRoIGZpbGw9IiNERDAwMzEiIGQ9Ik0xMjUgMzBMMzEuOSA2My4ybDE0LjIgMTIzLjFMMTI1IDIzMGw3OC45LTQzLjcgMTQuMi0xMjMuMXoiIC8+CiAgICA8cGF0aCBmaWxsPSIjQzMwMDJGIiBkPSJNMTI1IDMwdjIyLjItLjFWMjMwbDc4LjktNDMuNyAxNC4yLTEyMy4xTDEyNSAzMHoiIC8+CiAgICA8cGF0aCAgZmlsbD0iI0ZGRkZGRiIgZD0iTTEyNSA1Mi4xTDY2LjggMTgyLjZoMjEuN2wxMS43LTI5LjJoNDkuNGwxMS43IDI5LjJIMTgzTDEyNSA1Mi4xem0xNyA4My4zaC0zNGwxNy00MC45IDE3IDQwLjl6IiAvPgogIDwvc3ZnPg==">
8+
9+
<div>
10+
11+
<a uiSref="home" uiSrefActive="active">home</a>
12+
<a uiSref="about" uiSrefActive="active">about</a>
13+
<a uiSref="lazy" uiSrefActiveEq="active">lazy</a>
14+
<a uiSref="lazy.child" uiSrefActive="active">lazy.child</a>
15+
<a uiSref="lazy.child.viewtarget" uiSrefActive="active">lazy.child.viewtarget</a>
16+
</div>
17+
18+
<ui-view id="default"></ui-view>
19+
</div>
20+
21+
<ui-view name="footer" id="footer"></ui-view>
22+
`;
23+
324
@Component({
425
selector: 'app-root',
5-
templateUrl: './app.component.html',
6-
styleUrls: ['./app.component.css'],
26+
template: template,
27+
styles: [
28+
`
29+
.app {
30+
text-align: center;
31+
border: 1px solid;
32+
}
33+
34+
.active {
35+
font-weight: bold;
36+
}
37+
`,
38+
],
739
})
8-
export class AppComponent {
9-
title = 'app';
10-
}
40+
export class AppComponent {}
Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
import { BrowserModule } from '@angular/platform-browser';
2-
import { NgModule } from '@angular/core';
2+
import { NgModule, NgModuleFactoryLoader, SystemJsNgModuleLoader } from '@angular/core';
3+
import { UIRouterModule } from '@uirouter/angular';
4+
import { UIRouter } from '@uirouter/core';
35

46
import { AppComponent } from './app.component';
7+
import { HomeComponent } from './home.component';
8+
import { AboutComponent } from './about.component';
9+
10+
export const states = [
11+
{ name: 'home', url: '/home', component: HomeComponent },
12+
{ name: 'about', url: '/about', component: AboutComponent },
13+
{ name: 'lazy.**', url: '/lazy', loadChildren: './lazy/lazy.module#LazyModule' },
14+
];
15+
16+
export function config(router: UIRouter) {
17+
router.urlService.rules.initial({ state: 'home' });
18+
}
519

620
@NgModule({
7-
declarations: [AppComponent],
8-
imports: [BrowserModule],
9-
providers: [],
21+
imports: [BrowserModule, UIRouterModule.forRoot({ states, config })],
22+
providers: [{ provide: NgModuleFactoryLoader, useClass: SystemJsNgModuleLoader }],
23+
declarations: [AppComponent, HomeComponent, AboutComponent],
1024
bootstrap: [AppComponent],
1125
})
1226
export class AppModule {}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { Component } from '@angular/core';
2+
3+
@Component({
4+
selector: 'app-home',
5+
template: `<p>home works!</p>`,
6+
})
7+
export class HomeComponent {}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Component, Input } from '@angular/core';
2+
3+
@Component({
4+
selector: 'app-lazy',
5+
template: `
6+
<p>{{state.name}} works!</p>
7+
<ui-view></ui-view>
8+
`,
9+
})
10+
export class LazyComponent {
11+
@Input('$state$') state;
12+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { NgModule } from '@angular/core';
2+
import { CommonModule } from '@angular/common';
3+
import { UIRouterModule } from '@uirouter/angular';
4+
import { LazyComponent } from './lazy.component';
5+
6+
export const states = [
7+
{ name: 'lazy', url: '/lazy', component: LazyComponent },
8+
{ name: 'lazy.child', url: '/child', component: LazyComponent },
9+
{
10+
name: 'lazy.child.viewtarget',
11+
url: '/viewtarget',
12+
views: {
13+
'!header': { component: LazyComponent },
14+
'footer@': { component: LazyComponent },
15+
},
16+
},
17+
];
18+
19+
@NgModule({
20+
imports: [CommonModule, UIRouterModule.forChild({ states: states })],
21+
declarations: [LazyComponent],
22+
})
23+
export class LazyModule {}

0 commit comments

Comments
 (0)