-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(example): Added minimal example
- Loading branch information
1 parent
441ba7a
commit 425815d
Showing
9 changed files
with
2,707 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ node_modules | |
tsconfig.json | ||
rollup.config.js | ||
stats.html | ||
examples |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
run `npm install` then `npm start` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<html> | ||
<head> | ||
<script src="//unpkg.com/[email protected]/angular.js"></script> | ||
<script src="//unpkg.com/reflect-metadata"></script> | ||
<script src="//unpkg.com/zone.js"></script> | ||
</head> | ||
<body> | ||
<!-- the app will fill this ui-view --> | ||
<ui-view></ui-view> | ||
|
||
<!-- load webpack bundle in body tag after document.body is ready --> | ||
<script src="_bundles/app.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"scripts":{ | ||
"start": "webpack-dev-server --open" | ||
}, | ||
"dependencies": { | ||
"@angular/common": "^4.0.0", | ||
"@angular/compiler": "^4.0.0", | ||
"@angular/core": "^4.0.0", | ||
"@angular/platform-browser": "^4.0.0", | ||
"@angular/platform-browser-dynamic": "^4.0.0", | ||
"@angular/router": "^4.1.3", | ||
"@angular/upgrade": "^4.0.0", | ||
"@uirouter/angular-hybrid": "^3.1.1", | ||
"angular": "^1.6.4", | ||
"ts-loader": "^2.1.0", | ||
"webpack": "^2.6.1", | ||
"webpack-dev-server": "^2.4.5" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import * as angular from 'angular'; | ||
import { Component, NgModule } from '@angular/core'; | ||
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; | ||
import { UpgradeModule } from '@angular/upgrade/static'; | ||
import { BrowserModule } from '@angular/platform-browser'; | ||
import { UIRouterModule } from '@uirouter/angular'; | ||
import { UIRouterUpgradeModule } from '@uirouter/angular-hybrid'; | ||
import { UrlService} from '@uirouter/core'; | ||
|
||
|
||
var app = angular.module('minimal', ['ui.router.upgrade']); | ||
|
||
app.run(($stateRegistry, $urlService) => { | ||
$urlService.rules.initial({state: 'app'}); | ||
|
||
$stateRegistry.register({ | ||
url: '', | ||
name: 'app', | ||
template: ` | ||
<a ui-sref=".ng1" ui-sref-active-eq="active">app.ng1</a> | ||
<a ui-sref=".ng1.ng2" ui-sref-active-eq="active">app.ng1.ng2</a> | ||
<a ui-sref=".ng2" ui-sref-active-eq="active">app.ng2</a> | ||
<a ui-sref=".ng2.ng2" ui-sref-active-eq="active">app.ng2.ng2</a> | ||
<ui-view></ui-view> | ||
` | ||
}); | ||
|
||
// route to ng1 component | ||
$stateRegistry.register({ | ||
url: '/ng1', | ||
name: 'app.ng1', | ||
component: 'ng1Component', | ||
}); | ||
|
||
// nested route to ng2 component | ||
$stateRegistry.register({ | ||
url: '/ng2', | ||
name: 'app.ng1.ng2', | ||
component: Ng2Component, | ||
}); | ||
|
||
// route to ng2 component | ||
$stateRegistry.register({ | ||
url: '/ng2', | ||
name: 'app.ng2', | ||
component: Ng2Component, | ||
}); | ||
|
||
// nested route to ng2 component | ||
$stateRegistry.register({ | ||
url: '/ng2', | ||
name: 'app.ng2.ng2', | ||
component: Ng2Component, | ||
}); | ||
}); | ||
|
||
|
||
|
||
// An AngularJS component | ||
app.component('ng1Component', { | ||
template: ` | ||
<h1>ng1 component</h1> | ||
<a ui-sref="app">Back to app</a> | ||
<ui-view></ui-view> | ||
` | ||
}) | ||
|
||
// An Angular component | ||
@Component({ | ||
selector: 'ng2-component', | ||
template: ` | ||
<h1>ng2 component</h1> | ||
<a uiSref="app">Back to app</a> | ||
<ui-view></ui-view> | ||
` | ||
}) export class Ng2Component { } | ||
|
||
// The root Angular module | ||
@NgModule({ | ||
imports: [ | ||
BrowserModule, | ||
// Provide Angular upgrade capabilities | ||
UpgradeModule, | ||
// Provides the @uirouter/angular-hybrid directives | ||
UIRouterUpgradeModule, | ||
// Provides the @uirouter/angular directives | ||
UIRouterModule, | ||
], | ||
declarations: [Ng2Component], | ||
entryComponents: [Ng2Component], | ||
}) export class RootModule { | ||
ngDoBootstrap() { | ||
/* no body: this disables normal (non-hybrid) Angular bootstrapping */ | ||
} | ||
} | ||
|
||
// Using AngularJS config block, call `deferIntercept()`. | ||
// This tells UI-Router to delay the initial URL sync (until all bootstrapping is complete) | ||
app.config([ '$urlServiceProvider', $urlService => $urlService.deferIntercept() ]); | ||
|
||
// Manually bootstrap the Angular app | ||
platformBrowserDynamic().bootstrapModule(RootModule).then(platformRef => { | ||
const injector = platformRef.injector; | ||
const upgrade = injector.get(UpgradeModule) as UpgradeModule; | ||
|
||
// The DOM must be already be available | ||
upgrade.bootstrap(document.body, [app.name]); | ||
|
||
// Intialize the Angular Module (get() any UIRouter service from DI to initialize it) | ||
const url = injector.get(UrlService); | ||
|
||
// Instruct UIRouter to listen to URL changes | ||
url.listen(); | ||
url.sync(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"files": [ "src/main.ts" ], | ||
"compilerOptions": { | ||
"emitDecoratorMetadata": true, | ||
"experimentalDecorators": true, | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"target": "es5", | ||
"rootDir": "src", | ||
"outDir": "transpiled", | ||
"declaration": false, | ||
"sourceMap": true, | ||
"skipLibCheck": true, | ||
"lib": ["es6", "dom"] | ||
} | ||
} |
Oops, something went wrong.