在这里,我试图将“$scope.getCourse =’adobe’”的值传递给服务器,以便返回相应的课程详细信息,从中可以从响应数据中使用ng-repeat填充列表.但是当我插入“$scope.getCourse”以及servelet url时,以下代码失败.
var courseApp = angular.module('courseApp',[]); courseApp.controller('courseCtrl',['$scope','$http',function($scope,$http){ //$scope.getCourse = 'adobe'; //need to pass this value to the server; $http.post('javaServerlet',$scope.getCourse).success(function(data){ $scope.result = data.MainTopic; $scope.lessons = data.CourSEOutline; }) }])
来自服装的json格式
{ "MainTopic": "Adobe","RunningTime": "6h11min","Description": "Course Description comes here","CourSEOutline": [ { "Lessons" : "Lesson 1","Title" : "Introduction1","Duration" : "31m 27s"},{ "Lessons" : "Lesson 2","Title" : "Introduction2","Duration" : "56m 05s"},] }
请让我知道如何实现上述情景,我对于角度很新.
您的数据应该是一个键/对,尝试:
$http.post('javaServerlet',{course: $scope.getCourse})
该变量将在参数过程中到达服务器