Skip to content

Commit 97e35df

Browse files
crisbetokara
authored andcommitted
fix(input,cdk): a couple of server-side rendering errors (#5066)
1 parent f2de538 commit 97e35df

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

src/lib/core/observe-content/observe-content.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import 'rxjs/add/operator/debounceTime';
1919
@Injectable()
2020
export class MdMutationObserverFactory {
2121
create(callback): MutationObserver {
22-
return new MutationObserver(callback);
22+
return typeof MutationObserver === 'undefined' ? null : new MutationObserver(callback);
2323
}
2424
}
2525

@@ -59,11 +59,13 @@ export class ObserveContent implements AfterContentInit, OnDestroy {
5959
this._debouncer.next(mutations);
6060
});
6161

62-
this._observer.observe(this._elementRef.nativeElement, {
63-
characterData: true,
64-
childList: true,
65-
subtree: true
66-
});
62+
if (this._observer) {
63+
this._observer.observe(this._elementRef.nativeElement, {
64+
characterData: true,
65+
childList: true,
66+
subtree: true
67+
});
68+
}
6769
}
6870

6971
ngOnDestroy() {

src/lib/input/input-container.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
Inject
2121
} from '@angular/core';
2222
import {animate, state, style, transition, trigger} from '@angular/animations';
23-
import {coerceBooleanProperty} from '../core';
23+
import {coerceBooleanProperty, Platform} from '../core';
2424
import {FormGroupDirective, NgControl, NgForm} from '@angular/forms';
2525
import {getSupportedInputTypes} from '../core/platform/features';
2626
import {
@@ -213,6 +213,7 @@ export class MdInputDirective {
213213

214214
constructor(private _elementRef: ElementRef,
215215
private _renderer: Renderer2,
216+
private _platform: Platform,
216217
@Optional() @Self() public _ngControl: NgControl,
217218
@Optional() private _parentForm: NgForm,
218219
@Optional() private _parentFormGroup: FormGroupDirective) {
@@ -267,7 +268,12 @@ export class MdInputDirective {
267268
/** Determines if the component host is a textarea. If not recognizable it returns false. */
268269
private _isTextarea() {
269270
let nativeElement = this._elementRef.nativeElement;
270-
return nativeElement ? nativeElement.nodeName.toLowerCase() === 'textarea' : false;
271+
272+
// In Universal, we don't have access to `nodeName`, but the same can be achieved with `name`.
273+
// Note that this shouldn't be necessary once Angular switches to an API that resembles the
274+
// DOM closer.
275+
let nodeName = this._platform.isBrowser ? nativeElement.nodeName : nativeElement.name;
276+
return nodeName ? nodeName.toLowerCase() === 'textarea' : false;
271277
}
272278
}
273279

src/universal-app/kitchen-sink/kitchen-sink.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ <h2>Chips</h2>
8686
<h2>Datepicker</h2>
8787

8888
<md-input-container>
89-
<input mdInput [mdDatepicker]="birthday" placeholder="Birthday">
89+
<input type="text" mdInput [mdDatepicker]="birthday" placeholder="Birthday">
9090
<button mdSuffix [mdDatepickerToggle]="birthday"></button>
9191
<md-datepicker #birthday></md-datepicker>
9292
</md-input-container>
@@ -106,7 +106,7 @@ <h2>Icon</h2>
106106
<h2>Input</h2>
107107

108108
<md-input-container>
109-
<input mdInput placeholder="amount">
109+
<input type="number" mdInput placeholder="amount">
110110
<span mdPrefix>$&nbsp;</span>
111111
<span mdSuffix>.00</span>
112112
<md-hint>Dolla dolla bills</md-hint>

0 commit comments

Comments
 (0)