Skip to content

Commit

Permalink
fix(input,cdk): a couple of server-side rendering errors (#5066)
Browse files Browse the repository at this point in the history
  • Loading branch information
crisbeto authored and kara committed Jun 12, 2017
1 parent f2de538 commit 97e35df
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
14 changes: 8 additions & 6 deletions src/lib/core/observe-content/observe-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import 'rxjs/add/operator/debounceTime';
@Injectable()
export class MdMutationObserverFactory {
create(callback): MutationObserver {
return new MutationObserver(callback);
return typeof MutationObserver === 'undefined' ? null : new MutationObserver(callback);
}
}

Expand Down Expand Up @@ -59,11 +59,13 @@ export class ObserveContent implements AfterContentInit, OnDestroy {
this._debouncer.next(mutations);
});

this._observer.observe(this._elementRef.nativeElement, {
characterData: true,
childList: true,
subtree: true
});
if (this._observer) {
this._observer.observe(this._elementRef.nativeElement, {
characterData: true,
childList: true,
subtree: true
});
}
}

ngOnDestroy() {
Expand Down
10 changes: 8 additions & 2 deletions src/lib/input/input-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
Inject
} from '@angular/core';
import {animate, state, style, transition, trigger} from '@angular/animations';
import {coerceBooleanProperty} from '../core';
import {coerceBooleanProperty, Platform} from '../core';
import {FormGroupDirective, NgControl, NgForm} from '@angular/forms';
import {getSupportedInputTypes} from '../core/platform/features';
import {
Expand Down Expand Up @@ -213,6 +213,7 @@ export class MdInputDirective {

constructor(private _elementRef: ElementRef,
private _renderer: Renderer2,
private _platform: Platform,
@Optional() @Self() public _ngControl: NgControl,
@Optional() private _parentForm: NgForm,
@Optional() private _parentFormGroup: FormGroupDirective) {
Expand Down Expand Up @@ -267,7 +268,12 @@ export class MdInputDirective {
/** Determines if the component host is a textarea. If not recognizable it returns false. */
private _isTextarea() {
let nativeElement = this._elementRef.nativeElement;
return nativeElement ? nativeElement.nodeName.toLowerCase() === 'textarea' : false;

// In Universal, we don't have access to `nodeName`, but the same can be achieved with `name`.
// Note that this shouldn't be necessary once Angular switches to an API that resembles the
// DOM closer.
let nodeName = this._platform.isBrowser ? nativeElement.nodeName : nativeElement.name;
return nodeName ? nodeName.toLowerCase() === 'textarea' : false;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/universal-app/kitchen-sink/kitchen-sink.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ <h2>Chips</h2>
<h2>Datepicker</h2>

<md-input-container>
<input mdInput [mdDatepicker]="birthday" placeholder="Birthday">
<input type="text" mdInput [mdDatepicker]="birthday" placeholder="Birthday">
<button mdSuffix [mdDatepickerToggle]="birthday"></button>
<md-datepicker #birthday></md-datepicker>
</md-input-container>
Expand All @@ -106,7 +106,7 @@ <h2>Icon</h2>
<h2>Input</h2>

<md-input-container>
<input mdInput placeholder="amount">
<input type="number" mdInput placeholder="amount">
<span mdPrefix>$&nbsp;</span>
<span mdSuffix>.00</span>
<md-hint>Dolla dolla bills</md-hint>
Expand Down

0 comments on commit 97e35df

Please sign in to comment.