Skip to content

Ability to set attrs/properties on root element of a component #1009

@ajoslin

Description

@ajoslin

I have a <side-menu> component in 2.0.0-alpha.13. Currently, to set the open class on the side menu to show/hide it, I have to manually manipulate the dom element:

import {Component, Template, NgElement} from 'angular2/angular2';
@Component({
  selector: 'side-menu'
})
@Template({
  inline: `<div class="scroll-area">
    <content></content>
  </div>`
})
class SideMenu {
  constructor(@NgElement() el: NgElement) {
    this.element = el;
  }
  //drag logic ommitted...
  setOpen(isOpen) {
    this.isOpen = isOpen;
    this.element.domElement.classList[isOpen ? 'add' : 'remove']('open');    
  }
}

I'd like to be able to setup a [class.open]="isOpen" binding on my component's element instead of having to do this.

@mhevery suggested injecting @PropertySetter('class.open') setter: Function into the constructor, but that errors when used because the actual setter function tries to set domElement.class.open. And domElement.class does not exist.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions