用角度显示模块模式

wen*_*mva 2 javascript revealing-module-pattern angularjs

今天的代码让我再次疯狂,特别是Angular与Angular服务中的Revealing Module Pattern.当我开始时,我发现它没有任何问题...现在除了不工作......我不知道.任何方式都知道我想知道它是否有角度或者我做了一些愚蠢的事情.这是代码:

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
    };
});
Run Code Online (Sandbox Code Playgroud)

这就是所谓的地方:

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!"); 
}}]
Run Code Online (Sandbox Code Playgroud)

这就是firefox给我的手指:

[16:01:56.864] "Error: dataService.contentTypes.isReady is not a function
contentTypeCtrl<@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/</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<@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/<.then/<@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/</xhr.onreadystatechange@http://localhost:49499/Scripts/angular/angular.js:9304"
Run Code Online (Sandbox Code Playgroud)

救命?任何人??

以下是如何使用isready函数的示例:

    if (dataService.contentTypes.isReady() == false) {
    $scope.isBusy = true;
    dataService.contentTypes.get()
        .then(function () {
        }, function () {
            alert('contentTypes retrieval failed');
        })
        .then(function () {
            $scope.isBusy = false;
        });
}
Run Code Online (Sandbox Code Playgroud)

并使用这样的数据:

<tr data-ng-repeat="model in data.contentTypes.models">
Run Code Online (Sandbox Code Playgroud)

use*_*994 5

我不熟悉Angular,所以请原谅我离开这里( - !

看起来isReady()通过调用contentTypes()返回 - 但是我没有看到对contentTypes的调用 - 只有一个引用,它指向closure-fn _contentTypes.

这可能是下面的内容吗?

dataService.contentTypes().isReady()
Run Code Online (Sandbox Code Playgroud)

*添加'()'实际调用contentTypes函数,然后返回isReady()函数