我已經創建了此服務。 並使用** 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