fix(compiler): fix directive registration order

fix #328
This commit is contained in:
Victor Berchet
2015-01-09 18:48:28 +01:00
parent fd34a56347
commit b4338b623c
8 changed files with 71 additions and 52 deletions

View File

@ -79,6 +79,22 @@ export function main() {
});
});
// GH issue 328 - https://github.com/angular/angular/issues/328
it('should support different directive types on a single node', (done) => {
compiler.compile(MyComp, el('<child-cmp my-dir [elprop]="ctxProp"></child-cmp>')).then((pv) => {
createView(pv);
ctx.ctxProp = 'Hello World!';
cd.detectChanges();
var elInj = view.elementInjectors[0];
expect(elInj.get(MyDir).dirProp).toEqual('Hello World!');
expect(elInj.get(ChildComp).dirProp).toEqual(null);
done();
});
});
it('should support template directives via `<template>` elements.', (done) => {
compiler.compile(MyComp, el('<div><template let-some-tmpl="greeting"><copy-me>{{greeting}}</copy-me></template></div>')).then((pv) => {
createView(pv);
@ -145,8 +161,10 @@ class MyComp {
})
class ChildComp {
ctxProp:string;
dirProp:string;
constructor(service: MyService) {
this.ctxProp = service.greeting;
this.dirProp = null;
}
}

View File

@ -62,6 +62,14 @@ export function main() {
expect(results[0].componentDirective).toEqual(reader.read(SomeComponent));
});
it('component directives must be first in collected directives', () => {
var results = createPipeline().process(el('<div some-comp some-decor></div>'));
var dirs = results[0].getAllDirectives();
expect(dirs.length).toEqual(2);
expect(dirs[0]).toEqual(reader.read(SomeComponent));
expect(dirs[1]).toEqual(reader.read(SomeDecorator));
});
it('should detect them in property bindings', () => {
var pipeline = createPipeline({propertyBindings: {
'some-comp': 'someExpr'

View File

@ -56,7 +56,8 @@ export function main() {
if (isPresent(current.element.getAttribute('directives'))) {
hasBinding = true;
for (var i=0; i<directives.length; i++) {
current.addDirective(reflector.read(directives[i]));
var dirMetadata = reflector.read(directives[i]);
current.addDirective(dirMetadata);
}
}
if (hasBinding) {
@ -192,9 +193,9 @@ export function main() {
'boundprop2': 'prop2',
'boundprop3': 'prop3'
});
var directives = [SomeDecoratorDirectiveWith2Bindings,
var directives = [SomeComponentDirectiveWithBinding,
SomeTemplateDirectiveWithBinding,
SomeComponentDirectiveWithBinding];
SomeDecoratorDirectiveWith2Bindings];
var protoElementInjector = new ProtoElementInjector(null, 0, directives, true);
var pipeline = createPipeline({
propertyBindings: propertyBindings,

View File

@ -32,7 +32,8 @@ export function main() {
}
if (isPresent(current.element.getAttribute('directives'))) {
for (var i=0; i<directives.length; i++) {
current.addDirective(reader.read(directives[i]));
var dirMetadata = reader.read(directives[i]);
current.addDirective(dirMetadata);
}
}
current.inheritedProtoView = protoView;
@ -133,9 +134,11 @@ export function main() {
class TestableProtoElementInjectorBuilder extends ProtoElementInjectorBuilder {
debugObjects:List;
constructor() {
this.debugObjects = [];
}
findArgsFor(protoElementInjector:ProtoElementInjector) {
for (var i=0; i<this.debugObjects.length; i+=2) {
if (this.debugObjects[i] === protoElementInjector) {
@ -144,6 +147,7 @@ class TestableProtoElementInjectorBuilder extends ProtoElementInjectorBuilder {
}
return null;
}
internalCreateProtoElementInjector(parent, index, bindings, firstBindingIsComponent, distance) {
var result = new ProtoElementInjector(parent, index, bindings, firstBindingIsComponent, distance);
ListWrapper.push(this.debugObjects, result);