简体   繁体   English

如何将我的路线绑定到angular-material2中的步进器?

[英]How can I bind my route to a stepper in angular-material2?

I'm using the Stepper component of angular-material2 and I want the steps to be reflected in the URL route of my application, so that the users can share the URL links and get immediately to a proper step. 我正在使用angular-material2的Stepper组件 ,我希望这些步骤能够反映在我的应用程序的URL路由中,以便用户可以共享URL链接并立即获得正确的步骤。 Is it possible? 可能吗?

You need to inject and use Location service from '@angular/common' : 您需要从'@angular/common'注入并使用位置服务:

1) To change the URL call go function of Location service. 1)更改位置服务的URL调用go功能。 Example: 例:

if (this.stepper.selected.label === 'subscriber') { 
    this.location.go('./enrollment/subscriberInfo');
}

2) To change the stepper after URL change call subscriber function of Location service. 2)在URL更改后更改步进器,调用位置服务的用户功能。 Example: 例:

this.location.subscribe( () => {
    if (this.location.isCurrentPathEqualTo('/enrollment/subscriberInfo')) {
        this.stepper.selectedIndex = 0;
    }
    if (this.location.isCurrentPathEqualTo('/enrollment/payment')) {
        this.stepper.selectedIndex = 1;
    } 
    if (this.location.isCurrentPathEqualTo('/enrollment/agreement')) {
        this.stepper.selectedIndex = 2;
    }
});`

FYI, I used @Output() animationDone: EventEmitter<void> of stepper to change URL. 仅供参考,我使用了@Output() animationDone: EventEmitter<void>来更改URL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM