如何在angularjs中清除工厂的未知喷油器错误 [英] How to clear unknown injector error for factory in angularjs
本文介绍了如何在angularjs中清除工厂的未知喷油器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是AngularJs的新手。
注入工厂时我们收到了未知的提供程序错误。对于表单发布我提到了这个
版本:AngularJs 1.5.5
低于我的控制器和工厂。任何人都可以帮我解决。
我尝试过:
I am very new to AngularJs.
while injecting factory we are getting unknown provider error. For form posting i refered this
Version: AngularJs 1.5.5
Below my controller and factory. Can anyone help me to reolve.
What I have tried:
//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);
// ---
// PRVIATE METHODS.
// ---
// I serialize the given Object into a key-value pair string. This
// method expects an object and will default to the toString() method.
// --
// NOTE: This is an atered version of the jQuery.param() method which
// will serialize a data collection for Form posting.
// --
// https://github.com/jquery/jquery/blob/master/src/serialize.js#L45
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) {
------
}
推荐答案
scope','
http','
timeout','
timeout', '
这篇关于如何在angularjs中清除工厂的未知喷油器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文