【发布时间】:2015-10-09 19:32:57
【问题描述】:
我是 AngularJS 的新手。我已经包含了控制器、服务和调用其余服务的代码。请告知为什么呼叫没有到达休息服务。
我的代码如下:
app.config(function ($routeProvider) {
$routeProvider
.when('/addNewNote', {
controller: 'AddNewNoteController',
templateUrl:'views/addNote.html'
})
angularjs 控制器如下
app.controller('AddNewNoteController', ['$scope','savenote', function($scope,savenote) {
savenote.success(function(eData){
$scope.msg = eData;
调用http post rest服务的angular服务
app.factory('savenote',['$http',function($scope,$http){
return $http({
method: 'POST',
url: <url is pasted here>,
dataType: 'json',
data: {
"title" : "123dddd",
"contents" : "123ddddtttttt"
},
headers: { 'Content-Type': 'application/json; charset=UTF-8' }
})
}]);
这是休息服务
@Path("/savenote")
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public UserMessages saveNewNote(Note note) throws IOException {
.....
}
【问题讨论】:
标签: javascript json angularjs rest