本文整理匯總了TypeScript中angular2/router.Router.subscribe方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Router.subscribe方法的具體用法?TypeScript Router.subscribe怎麽用?TypeScript Router.subscribe使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類angular2/router.Router
的用法示例。
在下文中一共展示了Router.subscribe方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: constructor
constructor(private router: Router, private store: AppStore) {
// Whenever the Angular route has an event, dispatch an event with the new
// route data.
router.subscribe(value => {
// Don't show the side nav on the Sign In screen
this.hideNav = value.indexOf("sign-in") !== -1;
store.dispatch(routeChange(value));
// Clear the package search when the route changes
store.dispatch(setPackagesSearchQuery(""));
});
// Listen for changes on the state.
store.subscribe(state => {
// If the state has a requestedRoute attribute, use the router to navigate
// to the route that was requested.
const requestedRoute = state.router.requestedRoute;
if (requestedRoute) { router.navigate(requestedRoute); }
});
this.removeNotification = function(i) {
this.store.dispatch(removeNotification(i));
return false;
}.bind(this);
this.signOut = function() {
this.store.dispatch(signOut());
return false;
}.bind(this);
this.toggleUserNavMenu = function() {
this.store.dispatch(toggleUserNavMenu());
return false;
}.bind(this);
}
示例2: ngOnInit
ngOnInit(): void {
console.log(">>>> App OnInit");
this._router.subscribe((path) => {
console.log(">>>> Route Change: " + path);
});
}
示例3: applyBackWorkaround
// https://github.com/angular/angular/issues/7722
// https://github.com/angular/angular/issues/7873
private applyBackWorkaround() {
this._router.subscribe(() => {
setTimeout(() => {
this._applicationRef.tick();
});
});
}
示例4: constructor
constructor(router:Router) {
this.name = 'Alice';
router.subscribe((url) => console.log('Navigated'));
router.config( { 'path': '/home', 'component': Home } )
.then((_) => console.log("Home Registered"), err => console.log(err));
//.then(() => router.navigate('/home'), err => console.log(err));
}
示例5: constructor
constructor (public guestService: GuestService, private _router: Router, private _location: Location) {
// Hack to scroll top top on navigate.
// (autoscroll not yet implemented in ng2)
_router.subscribe(() => {
window.scrollTo(0, 0);
});
}
示例6: constructor
constructor(public router: Router) {
// subscribe to router url updates
router.subscribe((url) => {
// convert the current url into an instruction
this._getInstruction(url);
});
}
示例7: constructor
constructor(private _router: Router, private _authService: AuthService) {
this._router.subscribe(path => {
if (!this._authService.isAuthorised()) {
this._router.navigate(['/Landing']);
}
});
}
示例8: constructor
constructor(private _router: Router, private _title: Title)
{
this._router.subscribe((url) =>
{ //Fires on every URL change
this._title.setTitle(this.getCurrentTitle());
});
}
示例9: constructor
constructor(private _router: Router){
// listening for route change and changing application title based on the url.
this._router.subscribe((url: string)=>{
this.title = url.startsWith('project') ? 'Projects' : 'Dashboard';
});
}
示例10: constructor
constructor(private router:Router,
private location:Location,
private loginService:LoginService) {
this.isSignedIn = loginService.isSignedIn();
router.subscribe(() => {
this.isSignedIn = loginService.isSignedIn();
});
}