From 634b3bb88beec51d86dfde5228c95c57a54ba8af Mon Sep 17 00:00:00 2001 From: Pawel Kozlowski Date: Thu, 10 Nov 2016 00:21:27 +0100 Subject: [PATCH] feat(core): map 'for' attribute to 'htmlFor' property (#10546) This improves ergonomics a bit by allowing people to write: ``. This is similar to the existing class -> className mapping. Closes #7516 --- .../src/schema/dom_element_schema_registry.ts | 1 + .../@angular/core/test/linker/integration_spec.ts | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/modules/@angular/compiler/src/schema/dom_element_schema_registry.ts b/modules/@angular/compiler/src/schema/dom_element_schema_registry.ts index 9c18b62667..369311d07c 100644 --- a/modules/@angular/compiler/src/schema/dom_element_schema_registry.ts +++ b/modules/@angular/compiler/src/schema/dom_element_schema_registry.ts @@ -231,6 +231,7 @@ const SCHEMA: const _ATTR_TO_PROP: {[name: string]: string} = { 'class': 'className', + 'for': 'htmlFor', 'formaction': 'formAction', 'innerHtml': 'innerHTML', 'readonly': 'readOnly', diff --git a/modules/@angular/core/test/linker/integration_spec.ts b/modules/@angular/core/test/linker/integration_spec.ts index 6d0e07fa5e..ed15a3bdb6 100644 --- a/modules/@angular/core/test/linker/integration_spec.ts +++ b/modules/@angular/core/test/linker/integration_spec.ts @@ -217,6 +217,19 @@ function declareTests({useJit}: {useJit: boolean}) { expect(nativeEl).not.toHaveCssClass('initial'); }); + it('should consume binding to htmlFor using for alias', () => { + const template = ''; + const fixture = TestBed.configureTestingModule({declarations: [MyComp]}) + .overrideComponent(MyComp, {set: {template}}) + .createComponent(MyComp); + + const nativeEl = fixture.debugElement.children[0].nativeElement; + fixture.debugElement.componentInstance.ctxProp = 'foo'; + fixture.detectChanges(); + + expect(nativeEl.htmlFor).toBe('foo'); + }); + it('should consume directive watch expression change.', () => { TestBed.configureTestingModule({declarations: [MyComp, MyDir]}); const template = '' +