如何在angularjs中清除工厂的未知喷油器错误

时间:2016-09-20 06:47:24

标签: angularjs

我对AngularJs很新。 在注入工厂时,我们遇到了未知的提供程序错误。对于表单发布,我提到了这个Ben Nadal

版本:AngularJs 1.5.5

在我的控制器和工厂下面。任何人都可以帮我解决。

//Factory
angular.module('transformRequestService', [])
.factory('transformRequestAsFormAsPost',
function () {
// I prepare the request data for the form post.
function transformRequest(data, getHeaders) {
var headers = getHeaders();
headers["Content-type"] = "application/x-www-form-urlencoded; charset=utf-8";
return (serializeData(data));
}
// Return the factory value.
return (transformRequest);
// ---

function serializeData(data) {
// If this is not an object, defer to native stringification.
if (!angular.isObject(data)) {
return ((data == null) ? "" : data.toString());
}
var buffer = [];
// Serialize each key in the object.
for (var name in data) {
if (!data.hasOwnProperty(name)) {
continue;
}
var value = data[name];
buffer.push(
encodeURIComponent(name) +
"=" +
encodeURIComponent((value == null) ? "" : value)
);
}
// Serialize the buffer and clean it up for transportation.
var source = buffer
.join("&")
.replace(/%20/g, "+")
;
return (source);
}
});


//App.js
var routerApp = angular.module('myApp', ['ui.router'
, 'vendorLoginModule'
, 'ui.bootstrap'
, 'createUser'
, 'ui.grid'
, 'ui.grid.selection'
, 'ui.grid.exporter'
, 'ngLoadingSpinner'
, 'confirm'
, 'transformRequestService'
]);


//injecting in controller
angular.module('confirm', [])

.controller('confirmController', ['$scope', '$http', '$timeout', '$uibModal', '$log', '$state', '$filter', '$crypthmac', '$rootScope', '$sce', 'transformRequestAsFormAsPost ', function ($scope, $http, $timeout, $uibModal, $log, $state, $filter, $crypthmac, $rootScope, $sce, transformRequestAsFormAsPost) {
------

}

2 个答案:

答案 0 :(得分:0)

]

控制器中缺少

答案 1 :(得分:0)

您已在模块transformRequestAsFormAsPost上注册了transformRequestService工厂,但您不会将该模块作为您使用工厂的模块的依赖项,因此您无法使用其服务和工厂。

请改为:

// laying a dependency on 'transformRequestService' module
// results in the ability to use its services and factories
angular.module('confirm', ["transformRequestService"]);