我已经创建了此服务。 并使用** enrollments.getProperty(); **这个语句来调用这个服务,但它不工作我是新的角JS,请让我知道我犯了什么错误。Angular JS服务创建错误
var helloAjaxApp = angular.module("myApp", []);
helloAjaxApp.service('enrollments', [ '$scope', '$http', function ($scope, $http) {
\t
\t $http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=utf-8";
var enrollments = null;
enrollment();
$scope.enrollment=function() {
\t $http({
\t url : 'enrollments',
method : "GET"
}).then(function(response) {
\t enrollments = response.data;
alert("enrollments");
});
};
return {
getProperty: function() {
return enrollments;
},
setProperty: function(value) {
\t enrollments = value;
}
};
}]);
其中定义模块? –
var helloAjaxApp = angular.module(“myApp”,[]); – RD063
你得到的错误是什么? – Nitheesh