Skip to content

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

Closed

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.

Activity

  1. changed the title [-]Allow setting of attributes/properties on root element of a component[/-] [+]Setting of attributes/properties on root element of a component[/+] on Mar 19, 2015
  2. changed the title [-]Setting of attributes/properties on root element of a component[/-] [+]Setting of attrs/properties on root element of a component[/+] on Mar 19, 2015
  3. changed the title [-]Setting of attrs/properties on root element of a component[/-] [+]Ability to set attrs/properties on root element of a component[/+] on Mar 19, 2015
  4. ajoslin commented on Mar 19, 2015

    @ajoslin
    ContributorAuthor

    Duplicate of #1008

  5. mhevery commented on Mar 19, 2015

    @mhevery
    Contributor

    @pkozlowski-opensource both#1008 and #1009. I think that @PropertySetter('a.b') should go through same code path as [a.b]. Since we already have [a.b] this should be straight forward.

  6. angular-automatic-lock-bot commented on Sep 6, 2019

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  7. locked and limited conversation to collaborators on Sep 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions