Open emadd opened 9 years ago
Anything obviously wrong here?
My object factory...
(function() { 'use strict'; var module = angular.module('common.model.domain', []); module.factory('Domain', function() { var Domain = function(data) { //DEFAULT PROPERTIES this.domainId = 0; this.less = null; this.css = null; //EXTEND THIS OBJECT WITH CONSTRUCTOR DATA if(data && angular.isObject(this)){ angular.extend(this, data); } //CUSTOM METHODS this.lessObj = function(){ if(this.less === null){ return null; }else{ return JSON.parse(this.less); } }; }; return Domain; }); })();
Within my service...
var rDomains = Restangular.withConfig(function(config){ config.setRestangularFields({ id: 'domainId' }); }); rDomains.extendModel('config/domain', function(data){ return new Domain(data); }); var domains = Domains.all('config/domain'); DomainService.getList = function() { return domains.getList().then(function(results){ return results; }, function(err){ console.log('DomainService.getList error',err); }); }; DomainService.get = function(id) { return domains.one(id.toString()).get().then(function(result){ return result; }, function(err){ console.log('DomainService.get error',err); }); };
Use of service...
//fetching a list of objects uses extendModel DomainSvc.getList().then(function(domains){ return domains; }); //fetching one does not use extendModal DomainSvc.get($stateParams.itemIds).then(function(d){ return d; });
This looks like you might have a bug in the way you've set up the multiple factories. Can you please post a working Plunkr example?
Anything obviously wrong here?
My object factory...
Within my service...
Use of service...