2015-10-26 79 views
2

對象不支持屬性或方法 '查詢' 在角度

(function() { 
    angular.module("common.script").factory("expenseResource", ["$resource", expenseResource]); 

    function expenseResource($resource) { 

    var expenceCategory = function ($resource) { 
     return $resource("api/expenceCategory/:expenceCategoryId"); 
    } 

    return { 
     expenceCategory: expenceCategory 
    }; 
    } 

})(); 

控制器

(function() { 
    var app = angular.module("ExpenceManagerApp", ["ui.router", "common.script", "expenseResourceMock"]); 

    app.config(["$stateProvider","$urlRouterProvider", function ($stateProvider,$urlRouterProvider) { 

    $urlRouterProvider.otherwise("/"); 

    $stateProvider 
     .state("HomePage", { 
      url:"/", 
      templateUrl: "App/Main/homePage.html", 

     }) 
     .state("Settings", { 
      url: "/Settings", 
      templateUrl: "App/Expense/settingsPage.html", 

     }) 
    .state("expenceCategoryEdit", { 
     url: "/expenceCategoryEdit", 
     templateUrl: "App/Expense/editExpenseCategory.html", 
     controller: "editExpenseCategoryCtrl as vm", 
     resolve: { 
      expenseResource: "expenseResource", 
      expenseCategoryList: function (expenseResource) { 
       return expenseResource.expenceCategory.query().$promise; 
      } 
     } 
    }) 
    }]); 

}()); 
+0

能否請你解釋一下,你會遇到這樣的錯誤。錯誤在什麼時候被觸發? –

+0

'expenseResource.expenceCategory',你確定它有一個'c',其中所有其他地方都拼寫了's'嗎? –

回答

1

expenceCategory是一個函數,所以將其用作功能:

expenseResource.expenceCategory().query().$promise 

OR define exnceCategory a s:

return { 
    expenceCategory: expenceCategory() 
}; 

注意:您的服務每次啓動時都會創建新的$資源。它應該只是:

function expenseResource($resource) { 
     return $resource("api/expenceCategory/:expenceCategoryId"); 
} 

並在控制器:

expenseResource.query().$promise 
相關問題