mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-16 01:52:19 +08:00
refactor(demo): move the demo app
This commit is contained in:
57
packages/demos/angular/testing/router-stubs.ts
Normal file
57
packages/demos/angular/testing/router-stubs.ts
Normal file
@ -0,0 +1,57 @@
|
||||
/* tslint:disable:directive-selector */
|
||||
/* tslint:disable:component-selector */
|
||||
/* tslint:disable:use-host-property-decorator */
|
||||
/* tslint:disable:no-input-rename */
|
||||
// export for convenience.
|
||||
export { ActivatedRoute, Router, RouterLink, RouterOutlet} from '@angular/router';
|
||||
|
||||
import { Component, Directive, Injectable, Input } from '@angular/core';
|
||||
import { NavigationExtras } from '@angular/router';
|
||||
|
||||
@Directive({
|
||||
selector: '[routerLink]',
|
||||
host: {
|
||||
'(click)': 'onClick()'
|
||||
}
|
||||
})
|
||||
export class RouterLinkStubDirective {
|
||||
@Input('routerLink') linkParams: any;
|
||||
navigatedTo: any = null;
|
||||
|
||||
onClick() {
|
||||
this.navigatedTo = this.linkParams;
|
||||
}
|
||||
}
|
||||
|
||||
@Component({selector: 'router-outlet', template: ''})
|
||||
export class RouterOutletStubComponent { }
|
||||
|
||||
@Injectable()
|
||||
export class RouterStub {
|
||||
navigate(commands: any[], extras?: NavigationExtras) { }
|
||||
}
|
||||
|
||||
|
||||
// Only implements params and part of snapshot.params
|
||||
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
|
||||
|
||||
@Injectable()
|
||||
export class ActivatedRouteStub {
|
||||
|
||||
// ActivatedRoute.params is Observable
|
||||
private subject = new BehaviorSubject(this.testParams);
|
||||
params = this.subject.asObservable();
|
||||
|
||||
// Test parameters
|
||||
private _testParams: {};
|
||||
get testParams() { return this._testParams; }
|
||||
set testParams(params: {}) {
|
||||
this._testParams = params;
|
||||
this.subject.next(params);
|
||||
}
|
||||
|
||||
// ActivatedRoute.snapshot.params
|
||||
get snapshot() {
|
||||
return { params: this.testParams };
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user