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

Commit

Permalink
feat: update to angular2 beta1
Browse files Browse the repository at this point in the history
 - update dialog to use root renderer
  • Loading branch information
justindujardin committed Feb 6, 2016
1 parent 0c3e7ba commit 2362e79
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
40 changes: 29 additions & 11 deletions ng2-material/components/dialog/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import {
ElementRef,
Injectable,
ResolvedProvider,
Injector
RenderComponentType,
ViewEncapsulation,
Injector,
Renderer,
RootRenderer,
APPLICATION_COMMON_PROVIDERS
} from 'angular2/core';

import {Promise} from 'angular2/src/facade/async';
Expand All @@ -16,7 +21,6 @@ import {MdDialogContainer} from './dialog_container';
import {MdDialogBasic} from './dialog_basic';
import {MdBackdrop} from "../backdrop/backdrop";
import {DOM} from "angular2/src/platform/dom/dom_adapter";
import {Renderer} from "angular2/core";
import {Animate} from '../../core/util/animate';

export * from './dialog_config';
Expand All @@ -36,8 +40,22 @@ export * from './dialog_basic';
*/
@Injectable()
export class MdDialog {
constructor(public componentLoader: DynamicComponentLoader,
public renderer: Renderer) {

/**
* Unique id counter for RenderComponentType.
* @private
*/
static _uniqueId:number = 0;

/**
* Renderer for manipulating dialog and backdrop component elements.
* @private
*/
private _renderer: Renderer = null;

constructor(public componentLoader: DynamicComponentLoader,rootRenderer: RootRenderer) {
let type = new RenderComponentType(`__md-dialog-${MdDialog._uniqueId++}`, ViewEncapsulation.None, []);
this._renderer = rootRenderer.renderComponent(type);
}

private _defaultContainer = DOM.query('body');
Expand All @@ -56,7 +74,7 @@ export class MdDialog {
// Create the dialogRef here so that it can be injected into the content component.
var dialogRef = new MdDialogRef();

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

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

Expand All @@ -70,15 +88,15 @@ export class MdDialog {
// Create a DOM node to serve as a physical host element for the dialog.
var dialogElement = containerRef.location.nativeElement;

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

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

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

dialogRef.containerRef = containerRef;
Expand Down Expand Up @@ -114,9 +132,9 @@ export class MdDialog {
.then((componentRef) => {
let backdrop: MdBackdrop = componentRef.instance;
backdrop.clickClose = options.clickClose;
this.renderer.setElementClass(componentRef.location, 'md-backdrop', true);
this.renderer.setElementClass(componentRef.location, 'md-opaque', true);
this.renderer.setElementClass(componentRef.location, 'md-backdrop-absolute', !!options.container);
this._renderer.setElementClass(componentRef.location.nativeElement, 'md-backdrop', true);
this._renderer.setElementClass(componentRef.location.nativeElement, 'md-opaque', true);
this._renderer.setElementClass(componentRef.location.nativeElement, 'md-backdrop-absolute', !!options.container);
DOM.appendChild(options.container || this._defaultContainer, componentRef.location.nativeElement);
return backdrop.show().then(() => componentRef);
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"test": "npm install"
},
"dependencies": {
"angular2": "2.0.0-beta.0",
"angular2": "2.0.0-beta.1",
"es6-promise": "3.0.2",
"es6-shim": "0.33.13",
"reflect-metadata": "0.1.2",
Expand Down

0 comments on commit 2362e79

Please sign in to comment.