0
votes

I recently moved from ember 1.x to 2.6. I am not able to use addObject/pushObject like i used to.

Ember      : 2.6.2
jQuery     : 2.2.4

import Ember from 'ember';

export default Ember.Controller.extend({
    test: ['sibi', 'john'],

    init: function() {
        this.get('test').pushObject('sebastian');
    }
});

This throws an error like pushObject is not a function. What is the workaround? Thank you.

2
My guess is that "[]" does not initialize Ember compatible array anymore (prototype extensions). Probably you need to allow this behavior explicitly in your config file. By now try replacing test:['sibi', 'john'] using Ember.Array: test: Ember.A(['sibi', 'john']) - Pavol
As a random side note, it's generally bad practice to add an array reference to a class definition. All instances of that class created will share the same reference to that array. - Kingpin2k

2 Answers

8
votes

The extend prototypes option was false for some reason. You can read more about disabling prototype extensions in the guide.

EmberENV: {
      EXTEND_PROTOTYPES: {
        Array: true
      }
    }

Thank you!

4
votes

Check your package.json against ember-disable-prototype-extensions.

If your project is an addon project it had beed added by ember-cli. And you should live with it. (Use Ember.A whenever you need an Ember array.)

If your project is an application project, just remove this addon.