-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dialog): add a config option for passing in data (#2266)
* feat(dialog): add a config option for passing in data Adds the ability to pass in data to a dialog via the `data` property. While this was previously possible through the `dialogRef.componentInstance.someUserSuppliedProperty`, it wasn't the most intuitive. The new approach looks like this: ``` dialog.open(SomeDialog, { data: { hello: 'world' } }); class SometDialog { constructor(data: MdDialogData) { console.log(data['hello']); } } ``` Fixes #2181. * Switch to using an OpaqueToken. * chore: fix aot errors
- Loading branch information
1 parent
e5ca565
commit 29cbe61
Showing
7 changed files
with
81 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,24 @@ | ||
import {Injector} from '@angular/core'; | ||
import {Injector, OpaqueToken} from '@angular/core'; | ||
import {MdDialogRef} from './dialog-ref'; | ||
|
||
export const MD_DIALOG_DATA = new OpaqueToken('MdDialogData'); | ||
|
||
/** Custom injector type specifically for instantiating components with a dialog. */ | ||
export class DialogInjector implements Injector { | ||
constructor(private _dialogRef: MdDialogRef<any>, private _parentInjector: Injector) { } | ||
constructor( | ||
private _parentInjector: Injector, | ||
private _dialogRef: MdDialogRef<any>, | ||
private _data: any) { } | ||
|
||
get(token: any, notFoundValue?: any): any { | ||
if (token === MdDialogRef) { | ||
return this._dialogRef; | ||
} | ||
|
||
if (token === MD_DIALOG_DATA && this._data) { | ||
return this._data; | ||
} | ||
|
||
return this._parentInjector.get(token, notFoundValue); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters