Question Revised: 04/30/2015
I would like to define a new Ember.Object.extend()
somewhere in my Ember CLI project, so that I can make new object instances from it using a line like myObject.create()
Is it correct to store these in a directory like app/custom-objects
? and then i can do something like import myObject from './custom-objects/my-object'
Is an initializer required to register the object into ember, before I can import it?
Is my assumption here correct?
Initializer is not required.
You could define myObject
:
//app/custom-objects/my-object.js
import Ember from 'ember';
export default Ember.Object.extend({
name: 'DefaultName'
});
and then you could import it anywhere:
//app/pods/parent/children/controller.js
import Ember from 'ember';
import MyObject from '../../../custom-objects/my-object'
export default Ember.Controller.extend({
//...
myObj: MyObject.create({name: 'SuperName'}),
});
//app/pods/parent/children/template.hbs
name: {{myObj.name}} {{!-- => SuperName --}}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With