gpt4 book ai didi

javascript - Angular JS 不是函数错误

转载 作者:行者123 更新时间:2023-11-30 12:07:18 24 4
gpt4 key购买 nike

我是 Angular 的新手,我无法让这个工厂工作,我只是在另一个 Visual Studio 实例中使用 Web 服务。这是代码:

主要工厂:

nngmodule.factory('generaldataFactory', ['$http', function ($http, $httpProvider) {
var dataFactory = {};

dataFactory.getMethodWebService = function (pMethod, pUrl, pCache, pTimeout, pParams, pFunctionSuccess, pFunctionError) {
$http({
method: pMethod, url: pUrl, cache: pCache, timeout: pTimeout, params: pParams
}).then(pFunctionSuccess, pFunctionError);
};

return dataFactory;

}]);

个人工厂(使用上面一个)

  ngmodule.factory('miFactory', ['$http', function (generaldataFactory) {

var miFact = {};

miFact.GetNoticiasList = function (functionSuccess, functionError) {
return generaldataFactory.getMethodWebService("GET", 'http://localhost:40900/Noticias/GetNoticiasList', false, 25000, {}, functionSuccess, functionError);
};
miFact.FiltrarNoticias = function (id, functionSuccess, functionError) {
return generaldataFactory.getMethodWebService("GET", 'http://localhost:40900/Noticias/GetNoticiaById/', false, 25000, { 'id': id }, functionSuccess, functionError);
};

return miFact;

}]);


Controller :

ngmodule.controller('miController', function(miFactory) { var 作用域 = this;

var registerSuccess = function (response) {

}
var registerError = function (response) {

}

scope.noticiasList = {}
scope.noticiasList = miFactory.GetNoticiasList(registerSuccess,registerError);

});


错误:

TypeError: generaldataFactory.getMethodWebService is not a function
at Object.miFact.GetNoticiasList (MiFactory.js:6)
at new <anonymous> (controllers.js:13)
at Object.invoke (angular.js:4478)
at extend.instance (angular.js:9136)
at nodeLinkFn (angular.js:8248)
at compositeLinkFn (angular.js:7680)
at compositeLinkFn (angular.js:7684)
at publicLinkFn (angular.js:7555)
at angular.js:1662
at Scope.$eval (angular.js:15989)

最佳答案

没有注入(inject)必要的依赖项(这发生在多个文件中)。数组中的参数需要与工厂函数中的参数相匹配。

ngmodule.factory('miFactory', ['$http', function (generaldataFactory) {

如果你想使用generaldataFactory,你需要像这样注入(inject)它:

ngmodule.factory('miFactory', ['generaldataFactory', function (generaldataFactory) {

关于javascript - Angular JS 不是函数错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34812114/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com