How to pass data to dialog of angular material 2

后端 未结 5 1123
花落未央
花落未央 2020-11-29 03:25

I am using dialog box of angular material2.

I want to pass data to the opened component. Here is how I am opening dialog box on click of a button

let         


        
5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-29 03:54

    If you're using dialogs for HTTP data, remember RxJS and Observables is perfect for this issue.

    Dialog service:

        private _dialogDataSubj$ = new Subject();
        dialogData$ = this._dialogDataSubj$.asObservable()
    
        setDialogData(data: DialogData) {
            this._dialogDataSubj$.next(data)
        }
    

    In dialog HTML:

    
    

    I'm not sure if it's just me, but i couldn't update data in my material dialog with just dialog data reference (@Inject) ie.: dialogRef.data = newData.

提交回复
热议问题