Skip to content
This repository has been archived by the owner on Feb 2, 2019. It is now read-only.

Commit

Permalink
fix(dialog): null reference error when not specifying dialog config
Browse files Browse the repository at this point in the history
 - default init options as new MdDialogConfig() and have defaults represented in that class
 - remove config variable and use default initialized parameter `options`
 - use let and specify explicit types
  • Loading branch information
justindujardin committed Feb 20, 2016
1 parent c8778ff commit 6e60b34
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions ng2-material/components/dialog/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,39 +65,37 @@ export class MdDialog {
* @param options
* @returns Promise for a reference to the dialog.
*/
open(type: Type, elementRef: ElementRef, options: MdDialogConfig = null): Promise<MdDialogRef> {
var config = isPresent(options) ? options : new MdDialogConfig();

open(type: Type, elementRef: ElementRef, options: MdDialogConfig = new MdDialogConfig()): Promise<MdDialogRef> {
// Create the dialogRef here so that it can be injected into the content component.
var dialogRef = new MdDialogRef();
let dialogRef = new MdDialogRef();

var bindings = Injector.resolve([APPLICATION_COMMON_PROVIDERS, provide(MdDialogRef, {useValue: dialogRef})]);
let bindings = Injector.resolve([APPLICATION_COMMON_PROVIDERS, provide(MdDialogRef, {useValue: dialogRef})]);

var backdropRefPromise = this._openBackdrop(elementRef, bindings, options);
let backdropRefPromise = this._openBackdrop(elementRef, bindings, options);

// First, load the MdDialogContainer, into which the given component will be loaded.
return this.componentLoader.loadNextToLocation(MdDialogContainer, elementRef, bindings)
.then((containerRef: ComponentRef) => {
var dialogElement = containerRef.location.nativeElement;

this._renderer.setElementClass(dialogElement, 'md-dialog-absolute', !!config.container);
this._renderer.setElementClass(dialogElement, 'md-dialog-absolute', !!options.container);

DOM.appendChild(config.container || this._defaultContainer, dialogElement);
DOM.appendChild(options.container || this._defaultContainer, dialogElement);

if (isPresent(config.width)) {
this._renderer.setElementStyle(dialogElement, 'width', config.width);
if (isPresent(options.width)) {
this._renderer.setElementStyle(dialogElement, 'width', options.width);
}
if (isPresent(config.height)) {
this._renderer.setElementStyle(dialogElement, 'height', config.height);
if (isPresent(options.height)) {
this._renderer.setElementStyle(dialogElement, 'height', options.height);
}

dialogRef.containerRef = containerRef;

// Now load the given component into the MdDialogContainer.
return this.componentLoader.loadNextToLocation(type, containerRef.instance.contentRef, bindings)
.then((contentRef: ComponentRef) => {
Object.keys(config.context).forEach((key) => {
contentRef.instance[key] = config.context[key];
Object.keys(options.context).forEach((key) => {
contentRef.instance[key] = options.context[key];
});

// Wrap both component refs for the container and the content so that we can return
Expand Down Expand Up @@ -131,7 +129,7 @@ export class MdDialog {
/** Loads the dialog backdrop (transparent overlay over the rest of the page). */
_openBackdrop(elementRef: ElementRef, bindings: ResolvedProvider[], options: MdDialogConfig): Promise<ComponentRef> {
return this.componentLoader.loadNextToLocation(MdBackdrop, elementRef, bindings)
.then((componentRef) => {
.then((componentRef: ComponentRef) => {
let backdrop: MdBackdrop = componentRef.instance;
backdrop.clickClose = options.clickClose;
this._renderer.setElementClass(componentRef.location.nativeElement, 'md-backdrop', true);
Expand Down

0 comments on commit 6e60b34

Please sign in to comment.