0
我創建了一個Angular模塊,服務&控制器使用grunt縮小爲一個文件。該目錄是腳本/資料/ xxxxx.js它看起來如下:錯誤:嘗試從WEB API加載數據時出現[ng:areq]
模塊:
(function() {
'use strict';
angular.module('profileModule', ['profileServices']);
})();
服務:
(function() {
'use strict';
var profileServices = angular.module('profileServices', ['ngResource']);
profileServices.factory('Profiles', ['$resource',
function ($resource) {
return $resource('/api/profiles/', {}, {
query: { method: 'GET', params: {}, isArray: true }
});
}]);
})();
控制器:
(function() {
'use strict';
angular
.module('profileModule')
.controller('profileController', profileController);
profileController.$inject = ['$scope', 'Profiles'];
function profileController($scope, Profiles) {
$scope.profiles = Profiles.query();
}
})();
咕嚕配置來縮小:
module.exports = function (grunt) {
// load Grunt plugins from NPM
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
// configure plugins
grunt.initConfig({
uglify: {
my_target: {
files: {
'wwwroot/portal-min.js': [
'scripts/profile/profileModule.js',
'scripts/profile/profileController.js',
'scripts/profile/profileServices.js',
'scripts/**/*.js']
}
}
},
watch: {
scripts: {
files: ['scripts/**/*.js'],
tasks: ['uglify']
}
}
});
// define tasks
grunt.registerTask('default', ['uglify', 'watch']);
};
WEB API控制器:
[Route("api/[controller]")]
public class ProfilesController : Controller
{
// GET: api/values
[HttpGet]
public IEnumerable<Profile> Get()
{
return new List<Profile> {
new Profile
{
Id=1,
FirstName = "Star Wars",
LastName= "Lucas",
Email = "[email protected]"
},
new Profile
{
Id=2,
FirstName ="King Kong",
LastName ="Jackson",
Email = "[email protected]"
},
new Profile
{
Id =3,
FirstName ="Memento",
LastName ="Nolan",
Email = "[email protected]"
}
};
}
}
當運行它,我不斷收到一個錯誤:
[ng:areq] Argument 'profileController' is not a function, got undefined
這是否有與做縮小或者是什麼問題?我真的沒有看到它。剛剛開始使用AngularJS,所以任何輸入都被讚賞!
我包括縮小的javascript文件保持在腳本文件夾中的所有文件(因此通常控制器以及)。儘管如此,這可能是一個問題嗎? – Citroenfris
你有沒有試過它與未經審查的版本,看看你是否得到相同的錯誤? – vbouk
然後工作..所以問題是與縮小。 – Citroenfris