feat(compiler): allow setting attributes on a host element
Closes #1402
This commit is contained in:
4
modules/angular2/src/render/api.js
vendored
4
modules/angular2/src/render/api.js
vendored
@ -116,15 +116,17 @@ export class DirectiveMetadata {
|
||||
compileChildren:boolean;
|
||||
hostListeners:Map<string, string>;
|
||||
hostProperties:Map<string, string>;
|
||||
hostAttributes:Map<string, string>;
|
||||
properties:Map<string, string>;
|
||||
readAttributes:List<string>;
|
||||
type:number;
|
||||
constructor({id, selector, compileChildren, hostListeners, hostProperties, properties, readAttributes, type}) {
|
||||
constructor({id, selector, compileChildren, hostListeners, hostProperties, hostAttributes, properties, readAttributes, type}) {
|
||||
this.id = id;
|
||||
this.selector = selector;
|
||||
this.compileChildren = isPresent(compileChildren) ? compileChildren : true;
|
||||
this.hostListeners = hostListeners;
|
||||
this.hostProperties = hostProperties;
|
||||
this.hostAttributes = hostAttributes;
|
||||
this.properties = properties;
|
||||
this.readAttributes = readAttributes;
|
||||
this.type = type;
|
||||
|
@ -78,6 +78,13 @@ export class DirectiveParser extends CompileStep {
|
||||
this._bindHostProperty(hostPropertyName, directivePropertyName, current, directiveBinderBuilder);
|
||||
});
|
||||
}
|
||||
if (isPresent(directive.hostAttributes)) {
|
||||
MapWrapper.forEach(directive.hostAttributes, (hostAttrValue, hostAttrName) => {
|
||||
if (!DOM.hasAttribute(current.element, hostAttrName)) {
|
||||
DOM.setAttribute(current.element, hostAttrName, hostAttrValue);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (isPresent(directive.readAttributes)) {
|
||||
ListWrapper.forEach(directive.readAttributes, (attrName) => {
|
||||
elementBinder.readAttribute(attrName);
|
||||
|
2
modules/angular2/src/render/dom/convert.js
vendored
2
modules/angular2/src/render/dom/convert.js
vendored
@ -13,6 +13,7 @@ export function directiveMetadataToMap(meta: DirectiveMetadata): Map {
|
||||
['compileChildren', meta.compileChildren],
|
||||
['hostListeners', _cloneIfPresent(meta.hostListeners)],
|
||||
['hostProperties', _cloneIfPresent(meta.hostProperties)],
|
||||
['hostAttributes', _cloneIfPresent(meta.hostAttributes)],
|
||||
['properties', _cloneIfPresent(meta.properties)],
|
||||
['readAttributes', _cloneIfPresent(meta.readAttributes)],
|
||||
['type', meta.type],
|
||||
@ -32,6 +33,7 @@ export function directiveMetadataFromMap(map: Map): DirectiveMetadata {
|
||||
compileChildren: MapWrapper.get(map, 'compileChildren'),
|
||||
hostListeners: _cloneIfPresent(MapWrapper.get(map, 'hostListeners')),
|
||||
hostProperties: _cloneIfPresent(MapWrapper.get(map, 'hostProperties')),
|
||||
hostAttributes: _cloneIfPresent(MapWrapper.get(map, 'hostAttributes')),
|
||||
properties: _cloneIfPresent(MapWrapper.get(map, 'properties')),
|
||||
readAttributes: _cloneIfPresent(MapWrapper.get(map, 'readAttributes')),
|
||||
type: MapWrapper.get(map, 'type')
|
||||
|
Reference in New Issue
Block a user