I have a SPA project using John Papa's great HotTowel.
I have a listservice
module in the services
folder and function is like:
define(['services/logger', 'models/businessobject', 'config'],
function (logger, businessobject, config) {
...
}
Also I have a businessobject
module in the models
folder. But when I'm running the app in the listservice
module the value of the parameter businessobject
is null.
Is there anything I miss do to tell RequireJS
or Durandal/Amd
that the businessobject
module is there?
The content of businessobject.js
is like:
define(['services/logger'],
function(logger) {
var BusinessObject = function() {
var self = this;
self.id = ko.observable();
self.typeId = ko.observable();
self.descriptor = ko.observable();
self.isNullo = false;
return self;
};
return BusinessObject;
}
Also, using Firebug, I've checked that the businessobject
module is loaded to client.
Your BusinessObject is not being instantiated in any way. If you are trying to use it to expose various models than you can do so like this -
define([], function() {
var businessModels = {
businessObject: businessObject
};
return businessModels;
function businessObject(id, typeid, descriptor, isNullo) {
var self = this;
self.id = ko.observable(id);
self.typeId = ko.observable(typeid);
self.descriptor = ko.observable(descriptor);
self.isNullo = isnullo;
}
and then from your listservice
var myObj = new BusinessObject.businessObject(1, 2, 'my obj', false);
Or if you just want to have a single module for each model, which seems a bit bulky but surely can be done, you can leave your code as-is and instantiate it normally -
var myObj = new BusinessObject();