I use Ember-CLI to build my ember application, but I don't want to use Ember Data.
By default, when you type this command: ember generate model Person, ember-cli would create a js file under models named "person.js", and it will be a DS.extend(...). I don't want that, I want a plain ember object. So... I delete the person.js and create manually a js file named models.js (that's where I'm going to declare all my ember objects).
Here's what I have in models.js:
import Ember from "ember";
App.Person = Ember.Object.extend({
helloWorld: function() {
alert("Hi, my name is " + this.get('name'));
}
});
I have checked that "App" is available (there's a var named App declared in app.js -- generated by EmberCLI -- and it is exported).
So... now... I want to use it from my Route. I have something like this (in a js file named person.js under "routes"):
import Ember from 'ember';
export default Ember.Route.extend({
model: function() {
return App.Person.create({
name: "Tom Dale"
});
}
});
Well... it doesn't work. The console says: Error while processing route: person.index App is not defined ReferenceError: App is not defined.
Ok... I checked the generated js file (myproject.js): I found this:
define('infoleccion2015/tests/models/models.jshint', function () {
'use strict';
module('JSHint - models');
test('models/models.js should pass jshint', function() {
ok(false, 'models/models.js should pass jshint.\nmodels/models.js: line 3, col 1, \'App\' is not defined.\n\n1 error');
});
});
Turns out that "App" is not recognized anywhere (not even from models.js).
I'm new to EmberCLI. Can someone tell me what to do here? It's a strict requirement that we can't use Ember-Data.
Thanks!
Addition:
Thanks Daniel and Buck for the prompt reply, I've checked them and it works.
I'm still stubborn though, trying to put all the object definition in one single js file (models.js)... and I now I found out how.
First, you can create a js file, let's name it models.js. You don't have to put it under models/ directory; you can put it directly under app/.
Here's sample content of models.js:
import Ember from "ember";
var Estado = Ember.Object.extend({
describe: function() {
return "Hi, the estado is " + this.get("idEstado");
}.property("idEstado")
});
var Distrito = Ember.Object.extend({
describe: function() {
return "Hi, the distrito is " + this.get("idDistrito");
}.property("idDistrito")
});
var models = {
Estado: Estado,
Distrito: Distrito
};
export default models;
Then, in your Route javascript, you can use it this way:
import models from '../models';
export default Ember.Route.extend({
model: function() {
return models.Estado.findAll();
}
});
Just an alternative, in case you think having separate js file for each domain-model overkill for your project.
Thanks!