我想从我的服务器api获取一些json数据。网址是/ contacts。 我收到关于未知提供者的错误,但我不明白我在这里做错了什么。我再次修改了代码,但似乎再次发生。角度注射(未知供应商)
(function() {
var app = angular.module('test', ['ngRoute', 'Contacts', '$http']);
app.config(function($routeProvider, $locationProvider) {
$locationProvider.html5Mode(true);
$routeProvider
.when("/", {
templateUrl: "partials/main.html",
controller: "contactsCtrl"
})
.otherwise({redirectTo:"/"});
});
app.service('Contacts', function($scope, $http) {
this.data = null;
this.all = function() {
$http.get('/contacts').
success(function(data) {
$scope.contacts = data;
})
};
});
app.controller('contactsCtrl', function($scope, Contacts) {
Contacts.all().query(function(data) {
$scope.contacts = data;
});
});
}());
<table class="table table-bordered">
<thead>
<th>Firstname <input type="search" class="pull-right"></th>
</thead>
<tbody>
<tr ng-repeat="contact in contacts">
<td>
<a ng-href="/edit/{{ contact.firstname }}">{{ contact.firstname }}</a>
</td>
</tr>
</tbody>
</table>
'Contacts'是服务,服务不能依赖于模块,所以只需从这里删除'angular.module('test',['ngRoute','Contacts','$ http']);' – Grundy
非常感谢你 – pap