Skip to content

Instantly share code, notes, and snippets.

@KostyaEsmukov
Created February 9, 2017 19:02
Show Gist options
  • Save KostyaEsmukov/5c3f2e10da62e0970cf2d1943a1254a0 to your computer and use it in GitHub Desktop.
Save KostyaEsmukov/5c3f2e10da62e0970cf2d1943a1254a0 to your computer and use it in GitHub Desktop.
Fix for angular-universal 2.1.0-rc.1 [hidden] issue
// Monkeypatch [hidden] issue - NodeDomRenderer doesn't treat this attribute properly.
// https://github.com/angular/universal/pull/629/files
import { NodeDomRenderer, DomRenderer, isPresent } from 'angular2-universal/node';
let originalSetElementProperty = NodeDomRenderer.prototype.setElementProperty;
NodeDomRenderer.prototype.setElementProperty = function (
renderElement: any, propertyName: string, propertyValue: any) {
let _propertyName = propertyName;
let _propertyValue = propertyValue;
// Fix for passing in custom Object
if (this._isObject(propertyValue)) {
propertyValue = JSON.stringify(propertyValue);
} else if (typeof propertyValue === 'number') {
propertyValue.toString();
}
// Fix for issues caused by null passed in
if (propertyValue === null || propertyValue === undefined) {
propertyValue = false;
if (propertyName === 'innerHTML') {
propertyValue = '';
}
}
if (propertyName === 'hidden') {
if (isPresent(propertyValue)) {
// Follow Angular default behavior, true || string (of anything) will cause it to be hidden
if (propertyValue) {
return DomRenderer.prototype.setElementAttribute.call(this, renderElement,
propertyName, propertyValue.toString());
}
}
return;
}
return originalSetElementProperty.call(this, renderElement, _propertyName, _propertyValue);
};

Fix for the angular-universal 2.1.0-rc.1 [hidden] issue

Issue: angular/universal#612
Fix: angular/universal#629

How to use this patch:

Create the __patch.node.hidden.ts file and import it right after the polyfills.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment