本文整理汇总了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();
});
}