Mauricio Andrés
Mauricio Andrés

Reputation: 163

Why after adding $interval other call to funtions stop working?

I'm working on an app developed by other people, I don't have any documentation or any way to contact them, and I have this problem:

It's an angular application that need to be refreshed every minute, In other sections of the app, they are using $interval, but in this page if I try to use it, the calls to my WebAPI stop working and I recive this error:

WebApiFactory.getNoStatusOrders is not a function

I need your help to know why is this happening, here is my code:

angular.module('AssemblyLive').controller('overviewCarsWithoutStatus', [
'$scope', '$rootScope', '$location', 'WebApiFactory', "$interval", 'StatusPointMonitorFactory',
function ($scope, $rootScope, $location, $interval, WebApiFactory, StatusPointMonitorFactory) {
    ...
    var areas = {
        bodyShop1:"B000,B001,B020,B031,B200,B211,B220,B231,B300,B311,B320,B331,B370,B371,B375,B376,B380,B381,B383,B386,B390,B400,B401,B410,B420,B421,B425,B426,B430",
        bodyShop2: "B431,B435,B436,B440,B451,B500,B521,B540,B551,B553,B600,B750,B760,B770,B781,B783,B790,B791,B800,B811,B813,B900",
        paintShop1: "D000,D011,D012,D051,D100,D130,D131,D132,D151,D152,D230,D251,D252,D300,D351,D352,D360,D381,D390,D400,D451,D452,D470",
        paintShop2: "D471,D472,D481,D482,D500,D501,D531,D532,D540,D561,D562,D600,D620,D650,D670,D691,D692,D700,D731,D741,D750,D800,D812,D821,D822,D841,D842",
        assembly: "F000,F100,F150,F200,F250,F300,F350,F400,F450,F500,F550,F600,F650,F700,F750,F800,F850,F900"
    };
    ...
    //Start the creation of the overview.
    function initializeOverview() {
        $scope.counters = [];
        //Iterates over the configuration.

        //Get all the status to call the query.
        var status = $scope.headers.map(function(a) {return a.status.toString();});
        //Call to create the knrs b y area.
        getKNRWithoutStatus(status.toString());


        for(var status in areas){
            getCarsWithNoStatus(areas[status]);
        }

        getNoStatusCounters("B000,C000,D000,E000,E500,F000,F100,F950,G000,G900");

    }
    // Funtion to set the counters in the table headers
    function getNoStatusCounters(status) {
         WebApiFactory.getNoStatusOrdersCounter(status).then(function (resultData) {
            Object.getOwnPropertyNames(resultData.NoStatusOrders).forEach(function(name) {
    ...
    function getCarsWithNoStatus(status) {
        // Fetch all the counters from the WebAPI
        WebApiFactory.getNoStatusOrdersCounter(status).then(function (resultData) {
            ...

    function getKNRWithoutStatus(status) {
        var orders = [];
        //Query the status monitor.
        WebApiFactory.getNoStatusOrders(status).then(function(statusMonData) {
            ...

    /** To refresh data when the clock in the footer refresh. */
    $rootScope.$on('carsWithoutStatusOverview', function(){
        initializeOverview();
        $interval(initializeOverview, Config.dataRefreshInterval * 1000)
    });

Note: My page works perfectly without adding $interval

Upvotes: 0

Views: 34

Answers (1)

JC Ford
JC Ford

Reputation: 7066

Review your dependency injection. You put WebApiFactory and $interval in different positions in the $inject list and in the parameters. (So the $interval variable points to your WebApiFactory service and vice versa.)

Upvotes: 1

Related Questions