當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Router.subscribe方法代碼示例

本文整理匯總了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);

    }
開發者ID:OneOaaS,項目名稱:habitat,代碼行數:35,代碼來源:AppComponent.ts

示例2: ngOnInit

    ngOnInit(): void {
        console.log(">>>> App OnInit");    

        this._router.subscribe((path) => {
            console.log(">>>> Route Change: " + path); 
        });
    }
開發者ID:a2dude,項目名稱:route1,代碼行數:7,代碼來源:app.ts

示例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();
         });
     });
 }
開發者ID:artiso-solutions,項目名稱:vokabelchef-web,代碼行數:9,代碼來源:nativeIntegrationService.ts

示例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));
 }
開發者ID:lehmamic,項目名稱:Angular2-Test,代碼行數:7,代碼來源:app.ts

示例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);
     });
 }
開發者ID:vigie,項目名稱:wedding-webapp,代碼行數:7,代碼來源:app.component.ts

示例6: constructor

 constructor(public router: Router) {
   // subscribe to router url updates
   router.subscribe((url) => {
     // convert the current url into an instruction
     this._getInstruction(url);
   });
 }
開發者ID:179309463,項目名稱:AdminLTE-angular2,代碼行數:7,代碼來源:RouterState.ts

示例7: constructor

	constructor(private _router: Router, private _authService: AuthService) {
		this._router.subscribe(path => {
			if (!this._authService.isAuthorised()) {
				this._router.navigate(['/Landing']);
			}
	    });
	}
開發者ID:kamleshKumarVerma,項目名稱:Job-Tracker-Angular-2-,代碼行數:7,代碼來源:app.component.ts

示例8: constructor

	constructor(private _router: Router, private _title: Title) 
	{
		this._router.subscribe((url) => 
		{ //Fires on every URL change
			this._title.setTitle(this.getCurrentTitle());
		});
	}
開發者ID:SlothHub,項目名稱:Annotations,代碼行數:7,代碼來源:app.component.ts

示例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';
     });
 }
開發者ID:ramirescm,項目名稱:angular2-tutorial-app,代碼行數:7,代碼來源:app.component.ts

示例10: constructor

 constructor(private router:Router,
             private location:Location,
             private loginService:LoginService) {
   this.isSignedIn = loginService.isSignedIn();
   router.subscribe(() => {
     this.isSignedIn = loginService.isSignedIn();
   });
 }
開發者ID:ishara,項目名稱:angular2-app,代碼行數:8,代碼來源:Header.ts


注:本文中的angular2/router.Router.subscribe方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。