【发布时间】:2015-07-04 21:42:20
【问题描述】:
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;
});
}]);
【问题讨论】:
-
您的控制器参数的顺序与使用数组表示法声明的顺序不同。改变
$resource和$http的位置。 -
应该是 .controller('hsbccontroller', ['$scope','$http','$resource', function($scope,$http, $resource){
-
酷,感谢它的工作伙伴。使用 Rest API 在 angularJs 中工作是相当新的。非常感谢。
标签: javascript angularjs restful-url ngresource