@ -4,7 +4,7 @@ import {ListWrapper, MapWrapper, List, StringMapWrapper} from 'angular2/src/faca
|
||||
import {DOM} from 'angular2/src/dom/dom_adapter';
|
||||
import {ProtoElementInjector, PreBuiltObjects, DirectiveBinding} from 'angular2/src/core/compiler/element_injector';
|
||||
import {Parent, Ancestor} from 'angular2/src/core/annotations/visibility';
|
||||
import {EventEmitter, PropertySetter} from 'angular2/src/core/annotations/di';
|
||||
import {EventEmitter, PropertySetter, Attribute} from 'angular2/src/core/annotations/di';
|
||||
import {onDestroy} from 'angular2/src/core/annotations/annotations';
|
||||
import {Optional, Injector, Inject, bind} from 'angular2/di';
|
||||
import {ProtoView, View} from 'angular2/src/core/compiler/view';
|
||||
@ -107,6 +107,17 @@ class NeedsPropertySetter {
|
||||
}
|
||||
}
|
||||
|
||||
class NeedsAttribute {
|
||||
typeAttribute;
|
||||
titleAttribute;
|
||||
fooAttribute;
|
||||
constructor(@Attribute('type') typeAttribute: string, @Attribute('title') titleAttribute: string, @Attribute('foo') fooAttribute: string) {
|
||||
this.typeAttribute = typeAttribute;
|
||||
this.titleAttribute = titleAttribute;
|
||||
this.fooAttribute = fooAttribute;
|
||||
}
|
||||
}
|
||||
|
||||
class A_Needs_B {
|
||||
constructor(dep){}
|
||||
}
|
||||
@ -148,10 +159,11 @@ export function main() {
|
||||
return [lookupName(tree), children];
|
||||
}
|
||||
|
||||
function injector(bindings, lightDomAppInjector = null, shadowDomAppInjector = null, preBuiltObjects = null) {
|
||||
function injector(bindings, lightDomAppInjector = null, shadowDomAppInjector = null, preBuiltObjects = null, attributes = null) {
|
||||
if (isBlank(lightDomAppInjector)) lightDomAppInjector = appInjector;
|
||||
|
||||
var proto = new ProtoElementInjector(null, 0, bindings, isPresent(shadowDomAppInjector));
|
||||
proto.attributes = attributes;
|
||||
var inj = proto.instantiate(null, null);
|
||||
var preBuilt = isPresent(preBuiltObjects) ? preBuiltObjects : defaultPreBuiltObjects;
|
||||
|
||||
@ -566,5 +578,20 @@ export function main() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('static', () => {
|
||||
it('should be injectable', () => {
|
||||
var attributes = MapWrapper.create();
|
||||
MapWrapper.set(attributes, 'type', 'text');
|
||||
MapWrapper.set(attributes, 'title', '');
|
||||
|
||||
var inj = injector([NeedsAttribute], null, null, null, attributes);
|
||||
var needsAttribute = inj.get(NeedsAttribute);
|
||||
|
||||
expect(needsAttribute.typeAttribute).toEqual('text');
|
||||
expect(needsAttribute.titleAttribute).toEqual('');
|
||||
expect(needsAttribute.fooAttribute).toEqual(null);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ import {EventManager} from 'angular2/src/core/events/event_manager';
|
||||
import {Decorator, Component, Viewport, DynamicComponent} from 'angular2/src/core/annotations/annotations';
|
||||
import {Template} from 'angular2/src/core/annotations/template';
|
||||
import {Parent, Ancestor} from 'angular2/src/core/annotations/visibility';
|
||||
import {EventEmitter} from 'angular2/src/core/annotations/di';
|
||||
import {EventEmitter, Attribute} from 'angular2/src/core/annotations/di';
|
||||
|
||||
import {If} from 'angular2/src/directives/if';
|
||||
|
||||
@ -606,6 +606,26 @@ export function main() {
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should support static attributes', inject([AsyncTestCompleter], (async) => {
|
||||
tplResolver.setTemplate(MyComp, new Template({
|
||||
inline: '<input static type="text" title></input>',
|
||||
directives: [NeedsAttribute]
|
||||
}));
|
||||
compiler.compile(MyComp).then((pv) => {
|
||||
createView(pv);
|
||||
|
||||
var injector = view.elementInjectors[0];
|
||||
var needsAttribute = injector.get(NeedsAttribute);
|
||||
expect(needsAttribute.typeAttribute).toEqual('text');
|
||||
expect(needsAttribute.titleAttribute).toEqual('');
|
||||
expect(needsAttribute.fooAttribute).toEqual(null);
|
||||
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
|
||||
|
||||
});
|
||||
|
||||
// Disabled until a solution is found, refs:
|
||||
@ -902,3 +922,17 @@ class DecoratorListeningEvent {
|
||||
class IdComponent {
|
||||
id: string;
|
||||
}
|
||||
|
||||
@Decorator({
|
||||
selector: '[static]'
|
||||
})
|
||||
class NeedsAttribute {
|
||||
typeAttribute;
|
||||
titleAttribute;
|
||||
fooAttribute;
|
||||
constructor(@Attribute('type') typeAttribute: string, @Attribute('title') titleAttribute: string, @Attribute('foo') fooAttribute: string) {
|
||||
this.typeAttribute = typeAttribute;
|
||||
this.titleAttribute = titleAttribute;
|
||||
this.fooAttribute = fooAttribute;
|
||||
}
|
||||
}
|
||||
|
@ -46,6 +46,12 @@ export function main() {
|
||||
expect(MapWrapper.get(results[0].propertyBindings, 'a').source).toEqual('{{b}}');
|
||||
});
|
||||
|
||||
it('should detect static attributes', () => {
|
||||
var results = createPipeline().process(el('<div a="b" c></div>'));
|
||||
expect(MapWrapper.get(results[0].attributes, 'a')).toEqual('b');
|
||||
expect(MapWrapper.get(results[0].attributes, 'c')).toEqual('');
|
||||
});
|
||||
|
||||
it('should detect var- syntax', () => {
|
||||
var results = createPipeline().process(el('<template var-a="b"></template>'));
|
||||
expect(MapWrapper.get(results[0].variableBindings, 'b')).toEqual('a');
|
||||
|
Reference in New Issue
Block a user