Note that there are some explanatory texts on larger screens.

plurals
  1. PORevealing Module Pattern with Angular
    primarykey
    data
    text
    <p>Today code is driving me mad again especially the Angular with the Revealing Module Pattern in an Angular service. When I started I saw nothing wrong with it... now apart from not working... I don't know. Any way know I want to know if it's angular or me doing something stupid. here's the code:</p> <pre><code>angular.module('homeAdmin.services', []) .factory('dataService', function ($http, $q) { 'use strict'; function _contentTypes(){ var intialized = false; var _models = []; function _isReady() { return intialized; }; return { isReady: _isReady }; }; return { contentTypes: _contentTypes }; }); </code></pre> <p>And here's where it is called:</p> <pre><code>var contentTypeCtrl = ['$scope','$http','$window','dataService', function ($scope, $http, $window, dataService) { 'use strict'; $scope.isBusy = false; $scope.data = dataService; $scope.contentType = {}; $scope.name = 'Content Type'; $scope.init = function () { console.log('contentTypeCtrl initialized'); }; if (dataService.contentTypes.isReady() == false) { console.log("Hello let's load some data!"); }}] </code></pre> <p>And here's how firefox gives me the finger:</p> <pre><code>[16:01:56.864] "Error: dataService.contentTypes.isReady is not a function contentTypeCtrl&lt;@http://localhost:49499/App/plugins/home/admin/ngen/content-type-ctrl.js:12 invoke@http://localhost:49499/Scripts/angular/angular.js:2902 instantiate@http://localhost:49499/Scripts/angular/angular.js:2914 @http://localhost:49499/Scripts/angular/angular.js:4805 updateView@http://localhost:49499/Scripts/angular/angular-ui-router.js:1317 $ViewDirective/directive.compile/&lt;/eventHook@http://localhost:49499/Scripts/angular/angular-ui-router.js:1276 Scope.prototype.$broadcast@http://localhost:49499/Scripts/angular/angular.js:8307 $StateProvider/$get/transitionTo/$state.transition&lt;@http://localhost:49499/Scripts/angular/angular-ui-router.js:1067 qFactory/defer/deferred.promise.then/wrappedCallback@http://localhost:49499/Scripts/angular/angular.js:6846 qFactory/ref/&lt;.then/&lt;@http://localhost:49499/Scripts/angular/angular.js:6883 Scope.prototype.$eval@http://localhost:49499/Scripts/angular/angular.js:8057 Scope.prototype.$digest@http://localhost:49499/Scripts/angular/angular.js:7922 Scope.prototype.$apply@http://localhost:49499/Scripts/angular/angular.js:8143 done@http://localhost:49499/Scripts/angular/angular.js:9170 completeRequest@http://localhost:49499/Scripts/angular/angular.js:9333 createHttpBackend/&lt;/xhr.onreadystatechange@http://localhost:49499/Scripts/angular/angular.js:9304" </code></pre> <p>Help? Anyone??</p> <p>Here's an example how the isready function should be used:</p> <pre><code> if (dataService.contentTypes.isReady() == false) { $scope.isBusy = true; dataService.contentTypes.get() .then(function () { }, function () { alert('contentTypes retrieval failed'); }) .then(function () { $scope.isBusy = false; }); } </code></pre> <p>And consume the data like this:</p> <pre><code>&lt;tr data-ng-repeat="model in data.contentTypes.models"&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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