feat(core): map 'for' attribute to 'htmlFor' property (#10546)

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
This commit is contained in:
Pawel Kozlowski 2016-11-10 00:21:27 +01:00 committed by Victor Berchet
parent 4595a61aeb
commit 634b3bb88b
2 changed files with 14 additions and 0 deletions

View File

@ -231,6 +231,7 @@ const SCHEMA:
const _ATTR_TO_PROP: {[name: string]: string} = {
'class': 'className',
'for': 'htmlFor',
'formaction': 'formAction',
'innerHtml': 'innerHTML',
'readonly': 'readOnly',

View File

@ -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>' +