Skip to content

Commit

Permalink
feat(core): map 'for' attribute to 'htmlFor' property (#10546)
Browse files Browse the repository at this point in the history
This improves ergonomics a bit by allowing people to write:
`<label [for]="ctxProp"></label>`.
This is similar to the existing class -> className mapping.

Closes #7516
  • Loading branch information
pkozlowski-opensource authored and vicb committed Nov 9, 2016
1 parent 4595a61 commit 634b3bb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ const SCHEMA:

const _ATTR_TO_PROP: {[name: string]: string} = {
'class': 'className',
'for': 'htmlFor',
'formaction': 'formAction',
'innerHtml': 'innerHTML',
'readonly': 'readOnly',
Expand Down
13 changes: 13 additions & 0 deletions modules/@angular/core/test/linker/integration_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<label [for]="ctxProp"></label>';
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 = '<span>' +
Expand Down

0 comments on commit 634b3bb

Please sign in to comment.