repackaging: all the file moves
This commit is contained in:
24
modules/@angular/examples/router/ts/reuse/index.html
Normal file
24
modules/@angular/examples/router/ts/reuse/index.html
Normal file
@ -0,0 +1,24 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Routing Reuse Lifecycle Example</title>
|
||||
<base href="/">
|
||||
|
||||
<script src="http://cdn.rawgit.com/google/traceur-compiler/90da568c7aa8e53ea362db1fc211fbb4f65b5e94/bin/traceur-runtime.js"></script>
|
||||
<script src="http://cdnjs.cloudflare.com/ajax/libs/systemjs/0.18.4/system.js"></script>
|
||||
<script>System.config({ baseURL: '/', defaultJSExtensions: true});</script>
|
||||
<script src="/bundle/angular2.dev.js"></script>
|
||||
<script src="/bundle/router.dev.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<example-app>
|
||||
Loading...
|
||||
</example-app>
|
||||
<script>
|
||||
var filename = 'angular2/examples/router/ts/reuse/reuse_example';
|
||||
System.import(filename).then(function(m) {
|
||||
m.main();
|
||||
}, console.error.bind(console));
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
58
modules/@angular/examples/router/ts/reuse/reuse_example.ts
Normal file
58
modules/@angular/examples/router/ts/reuse/reuse_example.ts
Normal file
@ -0,0 +1,58 @@
|
||||
import {Component, provide} from 'angular2/core';
|
||||
import {bootstrap} from 'angular2/platform/browser';
|
||||
import {
|
||||
CanActivate,
|
||||
RouteConfig,
|
||||
ComponentInstruction,
|
||||
ROUTER_DIRECTIVES,
|
||||
CanReuse,
|
||||
RouteParams,
|
||||
OnReuse
|
||||
} from 'angular2/router';
|
||||
import {APP_BASE_HREF} from 'angular2/platform/common';
|
||||
|
||||
|
||||
// #docregion reuseCmp
|
||||
@Component({
|
||||
selector: 'my-cmp',
|
||||
template: `
|
||||
<div>hello {{name}}!</div>
|
||||
<div>message: <input id="message"></div>
|
||||
`
|
||||
})
|
||||
class MyCmp implements CanReuse,
|
||||
OnReuse {
|
||||
name: string;
|
||||
constructor(params: RouteParams) { this.name = params.get('name') || 'NOBODY'; }
|
||||
|
||||
routerCanReuse(next: ComponentInstruction, prev: ComponentInstruction) { return true; }
|
||||
|
||||
routerOnReuse(next: ComponentInstruction, prev: ComponentInstruction) {
|
||||
this.name = next.params['name'];
|
||||
}
|
||||
}
|
||||
// #enddocregion
|
||||
|
||||
|
||||
@Component({
|
||||
selector: 'example-app',
|
||||
template: `
|
||||
<h1>Say hi to...</h1>
|
||||
<a [routerLink]="['/HomeCmp', {name: 'naomi'}]" id="naomi-link">Naomi</a> |
|
||||
<a [routerLink]="['/HomeCmp', {name: 'brad'}]" id="brad-link">Brad</a>
|
||||
<router-outlet></router-outlet>
|
||||
`,
|
||||
directives: [ROUTER_DIRECTIVES]
|
||||
})
|
||||
@RouteConfig([
|
||||
{path: '/', component: MyCmp, name: 'HomeCmp'},
|
||||
{path: '/:name', component: MyCmp, name: 'HomeCmp'}
|
||||
])
|
||||
class AppCmp {
|
||||
}
|
||||
|
||||
|
||||
export function main() {
|
||||
return bootstrap(AppCmp,
|
||||
[provide(APP_BASE_HREF, {useValue: '/angular2/examples/router/ts/reuse'})]);
|
||||
}
|
36
modules/@angular/examples/router/ts/reuse/reuse_spec.ts
Normal file
36
modules/@angular/examples/router/ts/reuse/reuse_spec.ts
Normal file
@ -0,0 +1,36 @@
|
||||
import {verifyNoBrowserErrors, browser} from 'angular2/src/testing/e2e_util';
|
||||
import {expect} from 'angular2/testing';
|
||||
|
||||
function waitForElement(selector: string) {
|
||||
var EC = (<any>protractor).ExpectedConditions;
|
||||
// Waits for the element with id 'abc' to be present on the dom.
|
||||
browser.wait(EC.presenceOf($(selector)), 20000);
|
||||
}
|
||||
|
||||
describe('reuse example app', function() {
|
||||
|
||||
afterEach(verifyNoBrowserErrors);
|
||||
|
||||
var URL = 'angular2/examples/router/ts/reuse/';
|
||||
|
||||
it('should build a link which points to the detail page', function() {
|
||||
browser.get(URL);
|
||||
waitForElement('my-cmp');
|
||||
|
||||
element(by.css('#naomi-link')).click();
|
||||
waitForElement('my-cmp');
|
||||
expect(browser.getCurrentUrl()).toMatch(/\/naomi$/);
|
||||
|
||||
// type something into input
|
||||
element(by.css('#message')).sendKeys('long time no see!');
|
||||
|
||||
// navigate to Brad
|
||||
element(by.css('#brad-link')).click();
|
||||
waitForElement('my-cmp');
|
||||
expect(browser.getCurrentUrl()).toMatch(/\/brad$/);
|
||||
|
||||
// check that typed input is the same
|
||||
expect(element(by.css('#message')).getAttribute('value')).toEqual('long time no see!');
|
||||
});
|
||||
|
||||
});
|
Reference in New Issue
Block a user