Pass parameter to MdDialog in Angular Material 2

前端 未结 1 1746
孤独总比滥情好
孤独总比滥情好 2020-12-21 23:01

I\'m using Angular Material 2 and I want to open a dialog window with MdDialog which shows some information about a user stored in firebase.

@Injectable()
ex         


        
相关标签:
1条回答
  • 2020-12-21 23:39

    You faced with a circular dependency. (TweetDialogComponent --> TweetService --> TweetDialogComponent)

    You can work around by using an abstract class:

    base-tweet.service.ts

    import { ViewContainerRef } from '@angular/core';
    
    export abstract class BaseTweetService {
      getUser() {};
    
      sendTweet(viewContainerRef: ViewContainerRef) {}
    }
    

    app.module.ts

    { provide: BaseTweetService, useClass: TweetService },
    

    app.component.ts

    constructor(
        ...
        private tweetService: BaseTweetService, 
    

    tweet-dialog.component.ts

    constructor(
      ...
      private tweetService: BaseTweetService) {  
    

    tweet.service.ts

    export class TweetService implements BaseTweetService {
    

    See also

    • Angular2: 2 services depending on each other
    • Circular dependency with Angular 2 and SystemJS
    0 讨论(0)
提交回复
热议问题