feat(compiler): allow setting attributes on a host element
Closes #1402
This commit is contained in:
@ -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