feat(core): desugar [()] to [prop] and (prop-change)
BREAKING CHANGE Before ``` <cmp [(prop)]="field"> was desugared to <cmp [prop]="field" (prop)="field=$event"> ``` After ``` <cmp [(prop)]="field"> is desugared to <cmp [prop]="field" (prop-change)="field=$event"> ``` Closes #4658
This commit is contained in:
@ -361,7 +361,8 @@ class TemplateParseVisitor implements HtmlAstVisitor {
|
||||
|
||||
private _parseAssignmentEvent(name: string, expression: string, sourceInfo: string,
|
||||
targetMatchableAttrs: string[][], targetEvents: BoundEventAst[]) {
|
||||
this._parseEvent(name, `${expression}=$event`, sourceInfo, targetMatchableAttrs, targetEvents);
|
||||
this._parseEvent(`${name}-change`, `${expression}=$event`, sourceInfo, targetMatchableAttrs,
|
||||
targetEvents);
|
||||
}
|
||||
|
||||
private _parseEvent(name: string, expression: string, sourceInfo: string,
|
||||
|
@ -75,7 +75,7 @@ const controlNameBinding =
|
||||
selector: '[ng-control]',
|
||||
bindings: [controlNameBinding],
|
||||
inputs: ['name: ngControl', 'model: ngModel'],
|
||||
outputs: ['update: ngModel'],
|
||||
outputs: ['update: ngModelChange'],
|
||||
exportAs: 'form'
|
||||
})
|
||||
export class NgControlName extends NgControl implements OnChanges,
|
||||
|
@ -66,7 +66,7 @@ const formControlBinding =
|
||||
selector: '[ng-form-control]',
|
||||
bindings: [formControlBinding],
|
||||
inputs: ['form: ngFormControl', 'model: ngModel'],
|
||||
outputs: ['update: ngModel'],
|
||||
outputs: ['update: ngModelChange'],
|
||||
exportAs: 'form'
|
||||
})
|
||||
export class NgFormControl extends NgControl implements OnChanges {
|
||||
|
@ -37,7 +37,7 @@ const formControlBinding = CONST_EXPR(new Binding(NgControl, {toAlias: forwardRe
|
||||
selector: '[ng-model]:not([ng-control]):not([ng-form-control])',
|
||||
bindings: [formControlBinding],
|
||||
inputs: ['model: ngModel'],
|
||||
outputs: ['update: ngModel'],
|
||||
outputs: ['update: ngModelChange'],
|
||||
exportAs: 'form'
|
||||
})
|
||||
export class NgModel extends NgControl implements OnChanges {
|
||||
|
@ -282,7 +282,7 @@ export function main() {
|
||||
],
|
||||
[
|
||||
BoundEventAst,
|
||||
'prop',
|
||||
'propChange',
|
||||
null,
|
||||
'v = $event',
|
||||
'TestComp > div:nth-child(0)[[(prop)]=v]'
|
||||
@ -305,7 +305,7 @@ export function main() {
|
||||
],
|
||||
[
|
||||
BoundEventAst,
|
||||
'prop',
|
||||
'propChange',
|
||||
null,
|
||||
'v = $event',
|
||||
'TestComp > div:nth-child(0)[bindon-prop=v]'
|
||||
|
@ -839,9 +839,9 @@ export function main() {
|
||||
rootTC.debugElement.componentInstance.ctxProp = 'one';
|
||||
rootTC.detectChanges();
|
||||
|
||||
expect(dir.value).toEqual('one');
|
||||
expect(dir.control).toEqual('one');
|
||||
|
||||
ObservableWrapper.subscribe(dir.control, (_) => {
|
||||
ObservableWrapper.subscribe(dir.controlChange, (_) => {
|
||||
expect(rootTC.debugElement.componentInstance.ctxProp).toEqual('two');
|
||||
async.done();
|
||||
});
|
||||
@ -2072,15 +2072,13 @@ class ToolbarComponent {
|
||||
}
|
||||
}
|
||||
|
||||
@Directive({selector: '[two-way]', inputs: ['value: control'], outputs: ['control']})
|
||||
@Directive({selector: '[two-way]', inputs: ['control'], outputs: ['controlChange']})
|
||||
@Injectable()
|
||||
class DirectiveWithTwoWayBinding {
|
||||
control: EventEmitter;
|
||||
value: any;
|
||||
controlChange = new EventEmitter();
|
||||
control = null;
|
||||
|
||||
constructor() { this.control = new EventEmitter(); }
|
||||
|
||||
triggerChange(value) { ObservableWrapper.callNext(this.control, value); }
|
||||
triggerChange(value) { ObservableWrapper.callNext(this.controlChange, value); }
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
|
Reference in New Issue
Block a user