Javascript AngularJS控制器错误-:$http.get不是控制器节中的函数
您需要更改$http和$resource的位置 angularJS的工作原理是(如果以这种方式定义的话),angularJS尝试匹配提供给函数参数的字符串,以便它知道哪个参数是什么。 这基本上是为了缩小,这实际上会改变如下所示的变量:Javascript AngularJS控制器错误-:$http.get不是控制器节中的函数,javascript,angularjs,restful-url,ngresource,Javascript,Angularjs,Restful Url,Ngresource,您需要更改$http和$resource的位置 angularJS的工作原理是(如果以这种方式定义的话),angularJS尝试匹配提供给函数参数的字符串,以便它知道哪个参数是什么。 这基本上是为了缩小,这实际上会改变如下所示的变量: var hsbc = angular.module('hsbc',['ngResource','ngRoute']); hsbc.config(['$routeProvider','$locationProvider', function ($routeProv
var hsbc = angular.module('hsbc',['ngResource','ngRoute']);
hsbc.config(['$routeProvider','$locationProvider', function ($routeProvider, $locationProvider){
//console.log('config part working');
$routeProvider
.when('/login', {
controller: 'hsbccontroller',
templateUrl: 'modules/authentication/views/login.html',
hideMenus: true
})
.when('/gloabltranfer', {
controller: 'hsbccontroller',
templateUrl: 'modules/home/views/gloabltranfer.html'
})
.when('/tranferReq', {
controller: 'hsbccontroller',
templateUrl: 'modules/home/views/TransferRquest.html'
})
.when('/reviewdetail', {
controller: 'hsbccontroller',
templateUrl: 'modules/home/views/Reviewdetails.html'
})
.when('/confirmdetail', {
controller: 'hsbccontroller',
templateUrl: 'modules/home/views/confirmdetails.html'
})
.when('/', {
controller: 'hsbccontroller',
templateUrl: 'modules/authentication/views/login.html'
})
.otherwise({ redirectTo: '/login' });
}]).controller('hsbccontroller', ['$scope','$http','$resource', function($scope,$resource,$http){
//console.log('controller part working');
$http.get('http://localhost:8080/1/').success(function(data) {
alert(data);
$scope.greeting = data;
});
}]);
在这里,angularjs知道:
a表示$scope
b是$http
c是$resource
在您的例子中,它实际上是在尝试“$resource.get”,因此会给您带来错误。
进一步阅读查看给定文档页面上关于缩小的注释:
控制器参数的顺序与使用数组表示法声明的顺序不同。更改
$resource
和$http
的位置。它应该是.controller('hsbccontroller',['$scope','$http','$resource',function($scope,$http,$resource){很酷,感谢它的工作伙伴。使用Rest API在angularJs中工作非常新。非常感谢。
.controller('hsbccontroller', ['$scope','$http','$resource', function(a,b,c){
//console.log('controller part working');
a.get('http://localhost:8080/1/').success(function(data) {
alert(data);
$scope.greeting = data;
});
}]);