Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As I see from your example, </p> <ul> <li>you didn't define properly the <code>factory.</code> The <code>this</code> key used for <code>service</code></li> <li>in <code>testService.doLoadItems(callback);</code> replace with <code>testServiceMockConfig.doLoadItems(callback);</code></li> </ul> <p>The difference between <strong>service</strong> - <strong>factory</strong> - <strong>provider</strong> and definition you can find in this simple demo:</p> <p><kbd><a href="http://jsfiddle.net/pkozlowski_opensource/PxdSP/14/" rel="nofollow">Fiddle</a></kbd></p> <p><em>Fixed example:</em></p> <pre><code>angular.module('testServiceMockConfig', []) .factory('testServiceMockConfig', function () { console.log("setup cqrs mock config."); return{ doLoadItems : function (callback) { console.log("mock loading data"); if (!this.configuredLoadItems) { throw Error("The mock is not configured to loadItems()."); } callback(this.loadItemsError, this.loadItemsSuccess); }, whenLoadItems : function (success, error) { this.configuredLoadItems = true; this.loadItemsSuccess = success; this.loadItemsError = error; } } }); angular.module('testService', ['testServiceMockConfig']) .factory('testService', ['testServiceMockConfig', function (testServiceMockConfig) { console.log("mock version. testServiceMockConfig: "); return { loadItems : function (callback) { testServiceMockConfig.doLoadItems(callback); } } }]) angular.module('ItemApp', ['testService']) .controller('ItemsCtrl', ['$scope', 'testService', function ($scope, testService) { $scope.text = 'No items loaded'; testService.loadItems(function (error, items) { if (error) { $scope.text = "Error happened"; } $scope.text = ''; for (i = 0; i &lt; items.length; i++) { $scope.text = $scope.text + items[i].name; } }) }]); </code></pre> <p>Demo <kbd><a href="http://plnkr.co/edit/xf0zyj2ZOhCiDndbfF08?p=preview" rel="nofollow">Plunker</a></kbd></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload