Angular 2 and TypeScript Promises

后端 未结 5 1496
孤独总比滥情好
孤独总比滥情好 2021-02-03 22:45

I\'m trying to use the routerCanDeactivate function for a component in my app. The simple way to use it is as follows:

routerCanDeactivate() {
             


        
5条回答
  •  时光取名叫无心
    2021-02-03 23:34

    Can also be done out of the box in the Angular2+ world using Subjects:

    export class MyComponent {
      private subject: Subject;
    
      routerCanDeactivate(): PromiseLike {
        $('#modal').modal('show');
        return this.subject.toPromise();
      }
    
      handleRespone(res: boolean) {
        this.subject.next(res);
      }
    }
    

提交回复
热议问题