X Tutup
Skip to content

Commit 448264b

Browse files
DrMarcIItbosch
authored andcommitted
fix(core): fix type error in setElementProperty
Convert propertyValue to string when calling setElementAttribute. Closes #3279
1 parent 78fdf9a commit 448264b

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

modules/angular2/src/render/dom/dom_renderer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export class DomRenderer extends Renderer {
147147
// Reflect the property value as an attribute value with ng-reflect- prefix.
148148
if (this._reflectPropertiesAsAttributes) {
149149
this.setElementAttribute(location, `${REFLECT_PREFIX}${camelCaseToDashCase(propertyName)}`,
150-
propertyValue);
150+
`${propertyValue}`);
151151
}
152152
}
153153

modules/angular2/test/render/dom/dom_renderer_integration_spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,26 @@ export function main() {
146146
async.done();
147147
});
148148
}));
149+
150+
it('should reflect non-string property values as attributes if flag is set',
151+
inject([AsyncTestCompleter, DomTestbed], (async, tb) => {
152+
tb.compileAndMerge(someComponent,
153+
[
154+
new ViewDefinition({
155+
componentId: 'someComponent',
156+
template: '<input [title]="y">',
157+
directives: []
158+
})
159+
])
160+
.then((protoViewMergeMappings) => {
161+
var rootView = tb.createView(protoViewMergeMappings);
162+
var el = DOM.childNodes(rootView.hostElement)[0];
163+
tb.renderer.setElementProperty(elRef(rootView.viewRef, 1), 'maxLength', 20);
164+
expect(DOM.getAttribute(<HTMLInputElement>el, 'ng-reflect-max-length'))
165+
.toEqual('20');
166+
async.done();
167+
});
168+
}));
149169
});
150170

151171
if (DOM.supportsDOMEvents()) {

0 commit comments

Comments
 (0)
X Tutup