gpt4 book ai didi

javascript - 喷油器错误 : Failed to instantiate module servicesApp

转载 作者:行者123 更新时间:2023-12-03 04:04:10 27 4
gpt4 key购买 nike

我在 angularJS 中注入(inject)模块时遇到问题:

Uncaught Error: [$injector:modulerr] Failed to instantiate module Mainapp due to: Error: [$injector:modulerr] Failed to instantiate module servicesApp due to: Error: [$injector:nomod] Module 'servicesApp' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.

这是服务代码servicesApp.js:

'use strict';

var servicesApp = angular.module('servicesApp', []);

servicesApp.service('fileUpload', ['$http',function ($http) {

this.uploadFileToUrl = function(file, uploadUrl){
var data = new FormData();
data.append('file', file);

return $http.post(uploadUrl, data, {
transformRequest: angular.identity,
headers: { 'Content-Type': undefined }
}).then(function (results) {
console.log("done post "+results);
return results;
}).catch(function(e) {
console.log('failed to post: ', e);
throw e;
});
};

this.upFile=function(file){

var nameImg="";
var uploadUrl =urlAPI+"/files/uploadFile";

if( file != null){

nameImg =file.name;

this.uploadFileToUrl(file, uploadUrl);

}else{
nameImg="userDefault.png";
}

return nameImg;
};

}]);

这是指令代码directivesApp.js:

'use strict';

var directivesApp = angular.module('directivesApp', []);

directivesApp.directives('fileModel', ['$parse', function ($parse) {
return {
restrict: 'A',
link: function(scope, element, attrs) {
var model = $parse(attrs.fileModel);
var modelSetter = model.assign;

element.bind('change', function(){
scope.$apply(function(){
modelSetter(scope, element[0].files[0]);
});
});
}
};
}]);

这是主要代码Mainapp.js:

var app = angular.module('Mainapp', ['ngRoute','file-model','ui.bootstrap','ngMessages','angular-loading-bar','ngFileUpload','servicesApp',
'directivesApp']);
<小时/>

编辑1:

我更改了“directives‌​App”和“servicesApp”的位置,但仍然遇到同样的问题:

var app = angular.module('Mainapp', ['ngRoute','file-model','ui.bootstrap','ngMessages','angular‌​-loading-bar','ngFil‌​eUpload','directives‌​App','servicesApp'])‌​;
<小时/>

编辑2:

Uncaught TypeError: directivesApp.directives is not a function at directivesApp.js:13

directivesApp.directives('fileModel', ['$parse', function ($parse) { ..}

如何解决这个问题?如何在 Controller 中使用指令和服务?

谢谢,

最佳答案

语法应为指令,改变

来自

directivesApp.directives('fileModel', ['$parse', function ($parse) { ..}

directivesApp.directive('fileModel', ['$parse', function ($parse) { ..}

关于javascript - 喷油器错误 : Failed to instantiate module servicesApp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44633809/

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