@@ -243,6 +243,30 @@ export function main() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should support directives where a selector matches property binding', function(done) {
|
||||
tplResolver.setTemplate(MyComp,
|
||||
new Template({
|
||||
inline: '<p [id]="ctxProp"></p>',
|
||||
directives: [IdComponent]
|
||||
}));
|
||||
|
||||
compiler.compile(MyComp).then((pv) => {
|
||||
createView(pv);
|
||||
|
||||
ctx.ctxProp = 'some_id';
|
||||
cd.detectChanges();
|
||||
expect(view.nodes[0].id).toEqual('some_id');
|
||||
expect(DOM.getInnerHTML(view.nodes[0].shadowRoot.childNodes[0])).toEqual('Matched on id with some_id');
|
||||
|
||||
ctx.ctxProp = 'other_id';
|
||||
cd.detectChanges();
|
||||
expect(view.nodes[0].id).toEqual('other_id');
|
||||
expect(DOM.getInnerHTML(view.nodes[0].shadowRoot.childNodes[0])).toEqual('Matched on id with other_id');
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should support template directives via `<template>` elements.', (done) => {
|
||||
tplResolver.setTemplate(MyComp,
|
||||
new Template({
|
||||
@@ -714,3 +738,14 @@ class DecoratorListeningEvent {
|
||||
this.msg = msg;
|
||||
}
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: '[id]',
|
||||
bind: {'id': 'id'}
|
||||
})
|
||||
@Template({
|
||||
inline: '<div>Matched on id with {{id}}</div>'
|
||||
})
|
||||
class IdComponent {
|
||||
id: string;
|
||||
}
|
||||
|
||||
@@ -39,10 +39,14 @@ export function main() {
|
||||
if (isPresent(propertyBindings)) {
|
||||
StringMapWrapper.forEach(propertyBindings, (v, k) => {
|
||||
current.addPropertyBinding(k, parser.parseBinding(v, null));
|
||||
MapWrapper.set(current.attrs(), k, v);
|
||||
});
|
||||
}
|
||||
if (isPresent(variableBindings)) {
|
||||
current.variableBindings = MapWrapper.createFromStringMap(variableBindings);
|
||||
StringMapWrapper.forEach(variableBindings, (v, k) => {
|
||||
current.addVariableBinding(k, v);
|
||||
MapWrapper.set(current.attrs(), k, v);
|
||||
});
|
||||
}
|
||||
}), new DirectiveParser(annotatedDirectives)]);
|
||||
}
|
||||
@@ -89,7 +93,7 @@ export function main() {
|
||||
createPipeline().process(
|
||||
el('<div some-comp some-comp2></div>')
|
||||
);
|
||||
}).toThrowError('Multiple component directives not allowed on the same element - check <div some-comp some-comp2>');
|
||||
}).toThrowError('Multiple component directives not allowed on the same element - check <div some-comp some-comp2>');
|
||||
});
|
||||
|
||||
it('should not allow component directives on <template> elements', () => {
|
||||
|
||||
Reference in New Issue
Block a user