X Tutup
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion modules/angular2/src/core/compiler/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ export class AppView implements ChangeDispatcher, RenderEventDispatcher {
if (b.isElementProperty()) {
this.renderer.setElementProperty(elementRef, b.name, currentValue);
} else if (b.isElementAttribute()) {
this.renderer.setElementAttribute(elementRef, b.name, `${currentValue}`);
this.renderer.setElementAttribute(elementRef, b.name,
isPresent(currentValue) ? `${currentValue}` : null);
} else if (b.isElementClass()) {
this.renderer.setElementClass(elementRef, b.name, currentValue);
} else if (b.isElementStyle()) {
Expand Down
24 changes: 24 additions & 0 deletions modules/angular2/test/core/compiler/integration_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,30 @@ export function main() {
});
}));

it('should remove an attribute when attribute expression evaluates to null',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideView(MyComp,
new ViewMetadata({template: '<div [attr.foo]="ctxProp"></div>'}))

.createAsync(MyComp)
.then((rootTC) => {

rootTC.debugElement.componentInstance.ctxProp = 'bar';
rootTC.detectChanges();
expect(DOM.getAttribute(rootTC.debugElement.componentViewChildren[0].nativeElement,
'foo'))
.toEqual('bar');

rootTC.debugElement.componentInstance.ctxProp = null;
rootTC.detectChanges();
expect(DOM.hasAttribute(rootTC.debugElement.componentViewChildren[0].nativeElement,
'foo'))
.toBeFalsy();

async.done();
});
}));

it('should consume binding to property names where attr name and property name do not match',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideView(MyComp,
Expand Down
X Tutup