我无法从结果中的以下代码中获取数据,系统正在通过错误声明 ReturnController 未定义,有人请告诉我遗漏的内容我的代码,我是AJS的新手。
Angular JS服务
<div ng-app="mainApp">
<div ng-controller="MyController">
<p>Result: {{ReturnController}}</p>
</div>
</div>
<script>
var mainApp = angular.module("mainApp", []);
mainApp.controller('MyController', function (MyFactory, $scope, $log) {
$log.log("Inside Controller");
$scope.ReturnController = MyFactory.multiply();
});
mainApp.factory('MyFactory', ["$log","$http", function ($log,$http) {
var factory = {};
factory.multiply = function () {
$log.log("Inside factory");
$http({
method: 'Get',
url: 'http://jsonplaceholder.typicode.com/posts/1',
}).then(function successCallback(response) {
$log.log("inside success");
var restdata = response.data;
$log.log(restdata.body);
return restdata.body;
}, function errorCallback(response) {
$log.log("Failed");
return response.status;
});
}
return factory;
}]);
</script>