feat(compiler): added support for [()] syntax
This commit is contained in:
@ -603,6 +603,30 @@ export function main() {
|
||||
});
|
||||
}));
|
||||
|
||||
it('should support [()] syntax', inject([TestBed, AsyncTestCompleter], (tb, async) => {
|
||||
tb.overrideView(MyComp, new View({
|
||||
template: '<div [(control)]="ctxProp" two-way></div>',
|
||||
directives: [DirectiveWithTwoWayBinding]
|
||||
}));
|
||||
|
||||
tb.createView(MyComp, {context: ctx}).then((view) => {
|
||||
var injector = view.rawView.elementInjectors[0];
|
||||
var dir = injector.get(DirectiveWithTwoWayBinding);
|
||||
|
||||
ctx.ctxProp = 'one';
|
||||
view.detectChanges();
|
||||
|
||||
expect(dir.value).toEqual('one');
|
||||
|
||||
ObservableWrapper.subscribe(dir.control, (_) => {
|
||||
expect(ctx.ctxProp).toEqual('two');
|
||||
async.done();
|
||||
});
|
||||
|
||||
dir.triggerChange('two');
|
||||
});
|
||||
}));
|
||||
|
||||
if (DOM.supportsDOMEvents()) {
|
||||
it("should support invoking methods on the host element via hostActions", inject([TestBed, AsyncTestCompleter], (tb, async) => {
|
||||
tb.overrideView(MyComp, new View({
|
||||
@ -1529,3 +1553,21 @@ class ToolbarComponent {
|
||||
this.query = query;
|
||||
}
|
||||
}
|
||||
|
||||
@Directive({
|
||||
selector: '[two-way]',
|
||||
properties: {value: 'control'},
|
||||
events: ['control']
|
||||
})
|
||||
class DirectiveWithTwoWayBinding {
|
||||
control:EventEmitter;
|
||||
value:any;
|
||||
|
||||
constructor() {
|
||||
this.control = new EventEmitter();
|
||||
}
|
||||
|
||||
triggerChange(value) {
|
||||
ObservableWrapper.callNext(this.control, value);
|
||||
}
|
||||
}
|
||||
|
@ -149,6 +149,18 @@ export function main() {
|
||||
expect(MapWrapper.get(results[0].attrs(), 'a')).toEqual('b');
|
||||
expect(MapWrapper.get(results[0].attrs(), 'c')).toEqual('d');
|
||||
});
|
||||
|
||||
it('should detect [()] syntax', () => {
|
||||
var results = process(el('<div [(a)]="b"></div>'));
|
||||
expect(MapWrapper.get(results[0].propertyBindings, 'a').source).toEqual('b');
|
||||
expect(results[0].eventBindings[0].source.source).toEqual('b=$event');
|
||||
});
|
||||
|
||||
it('should detect bindon- syntax', () => {
|
||||
var results = process(el('<div bindon-a="b"></div>'));
|
||||
expect(MapWrapper.get(results[0].propertyBindings, 'a').source).toEqual('b');
|
||||
expect(results[0].eventBindings[0].source.source).toEqual('b=$event');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user