Search code examples
angularjshottowel

Angular HotTowel -datacontext is not defined


**

Can anyone tell why I am getting the following?

**

[shell]  Hottowel Angular loaded! null

TypeError: undefined is not a function at Object.fn (/Scripts/app/services/directives.js:162:33) at Scope.$digest (/Scripts/angular.js:12251:29) at Scope.$apply (/Scripts/angular.js:12516:24) at done (/Scripts/angular.js:8204:45) at completeRequest (/Scripts/angular.js:8412:7) at XMLHttpRequest.xhr.onreadystatechange (/Scripts/angular.js:8351:11) undefined [app] [HT Error] undefined is not a function Object ReferenceError: datacontext is not defined at getMessageCount (/Scripts/app/dashboard/dashboard.js:29:20) at activate (/Scripts/app/dashboard/dashboard.js:23:29) at new dashboard (/Scripts/app/dashboard/dashboard.js:20:9) at invoke (/Scripts/angular.js:3869:17) at Object.instantiate (/Scripts/angular.js:3880:23) at /Scripts/angular.js:7134:28 at /cripts/angular.js:6538:34 at forEach (Scripts/angular.js:330:20) at nodeLinkFn (Scripts/angular.js:6525:11) at compositeLinkFn (/Scripts/angular.js:5986:15) [app] [HT Error] datacontext is not defined Object

Below is my includes

 <!-- Vendor Scripts -->
<script src="../Scripts/jquery-2.1.1.js"></script>
<script src="../Scripts/angular.js"></script>
<script src="../Scripts/angular-route.js"></script>
<script src="../Scripts/angular-animate.js"></script>
<script src="../Scripts/angular-sanitize.min.js"></script>
<script src="../Scripts/bootstrap.js"></script>
<script src="../Scripts/toastr.min.js"></script>
<script src="../Scripts/ui-bootstrap-0.6.0.js"></script>

<!-- PouchDB -->
<script src="../Scripts/angular-pouchdb.js"></script>

<!-- Bootstrapping -->
<script src="../Scripts/app/app.js"></script>
<script src="../Scripts/app/config.js"></script>
<script src="../Scripts/app/config.exceptionHandler.js"></script>
<script src="../Scripts/app/config.route.js"></script>

    <!--common Modules -->
<script src="../Scripts/app/common/common.js"></script>
<script src="../Scripts/app/common/logger.js"></script>
<script src="../Scripts/app/common/spinner.js"></script>

<!-- common.bootstrap Modules -->
<script src="../Scripts/app/common/bootstrap/bootstrap.dialog.js"></script>


<!-- app -->
<script src="../Scripts/app/dashboard/dashboard.js"></script>
<script src="../Scripts/app/layout/shell.js"></script>
<script src="../Scripts/app/layout/sidebar.js"></script>

<!-- app Services -->
<script src="../Scripts/app/services/datacontext.js"></script>
<script src="../Scripts/app/services/directives.js"></script>

My dash board is below

var controllerId = 'dashboard';
angular.module('app').controller(controllerId, ['common', 'datacontext', dashboard]);

function dashboard(common) {
    var getLogFn = common.logger.getLogFn;
    var log = getLogFn(controllerId);

    var vm = this;
    vm.news = {
        title: 'Hot Towel Angular',
        description: 'Hot Towel Angular is a SPA template for Angular developers.'
    };
    vm.messageCount = 0;
    vm.people = [];
    vm.title = 'Dashboard';

    //Call Active Init
    activate();

    function activate() {
        var promises = [getMessageCount(), getPeople()];
        common.activateController(promises, controllerId)
            .then(function () { log('Activated Dashboard View'); });
    }

    function getMessageCount() {
        return datacontext.getMessageCount().then(function (data) {
            return vm.messageCount = data;
        });

    }

    function getPeople() {
        return datacontext.getPeople().then(function (data) {
            return vm.people = data;
        });

    }
}

})();

Why is datacontext undefined?


Solution

  • You are not loading it in the dashboard definition

    Here, you are defining a controller, and injecting two dependencies, common and datacontext, which is good:

    angular.module('app').controller(controllerId, ['common', 'datacontext', dashboard]);
    

    But here, you are defining the dashboard function (the last parameter in the controller definition) to only have one parameter:

    function dashboard(common)
    

    ....so that datacontext that you are injecting is actually being ignored. You should change the dashboard definition to this:

    function dashboard(common, datacontext) {
       ...
    }