错误:[ng:areq]试图从WEB API加载数据
Error: [ng:areq] when trying to load data from WEB API
我已经创建了一个Angular模块Service &使用grunt将这些控制器缩小为一个文件。目录为scripts/profile/xxxxx.js,如下所示:<<p> 模块/strong>:
(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();
}
})();
Grunt config to minify:
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 Controller:
[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 = "test@test.be"
},
new Profile
{
Id=2,
FirstName ="King Kong",
LastName ="Jackson",
Email = "test@test.be"
},
new Profile
{
Id =3,
FirstName ="Memento",
LastName ="Nolan",
Email = "test@test.be"
}
};
}
}
当运行它时,我一直得到一个错误:
[ng:areq]参数'profileController'不是一个函数,得到未定义的
这与最小化有关还是有什么问题?我真的看不出来。刚开始使用AngularJS,所以任何输入都很感谢!
也许您忘记将控制器js文件包含到index.html
<script src="path_to_controller/profileController.js"></script>
相关文章:
- Steam Web API:I'我不知道该如何处理这个看起来像哈希的url来生成图像
- 如何在visualstudio中调试web api时编辑javascript文件
- 将复杂对象从angular js传递到web api,它总是返回404
- 将文档上载到Web API
- 对/Token的ASP Web API调用间歇性
- 从其他域和计算机发布的 Web API 帖子
- Web API 调用在设备模式下失败
- Testing .NET Web API from JavaScript
- 将日期作为从 Web API 到 angularJS 的 json 响应
- 获取 Spotify 用户 [Web API] 当前播放的曲目名称
- 在我的 Web API 中无法获取我的自定义标头
- Json 参数强制转换继承 Web API 2.
- 使用来自AngularJS的Web API JSON响应-错误:应为和数组,但得到了一个对象
- Javascript in Visual studio Web Api
- 获取AJAX中未定义的值(x),web api
- Web API在JSON调用上返回XML
- 将JSON字符串发布到WEB API
- 如何通过AngularJS$http从ASP.Net Web API 2获取访问令牌
- 使用ASP.Net MVC Web Api将JSON数据导出到Excel工作表
- 从mvc web api httpresponse生成csv,并通过angularjs接收下载