简体   繁体   中英

Set attribute to Ember Component

I want to set the draggable attribute to the component div itself.

In previous versions of ember (pre 1.13) I am used to use the attributeBindings property. But since 1.13 this property seems to be deprecated.

There are new lifecyle hooks for components ( http://emberjs.com/blog/2015/06/12/ember-1-13-0-released.html#toc_component-lifecycle-hooks ) but that didnt helped me either.

didInitAttrs() {
    this.set('draggable', true);
}

What is the prefered way to achieve this behavior?

UPDATE

In the meantime this is my solution:

import Ember from 'ember';

export default Ember.Component.extend({
  draggable: true,

  willInsertElement() {
    this.set('element.draggable', this.get('draggable'));
  }
});

AttributeBindings are not deprecated or you would get warnings when using them with components.

The property just happens to be inherited from ember views which are going away in 2.4 (long time away), but it doesn't mean the inherited interfaces on the components will go away without any deprecation notice. So just keep using attributeBindings .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM