数据未显示在控制器Angular Js

时间:2016-09-19 01:17:07

标签: javascript angularjs

我无法从结果中的以下代码中获取数据,系统正在通过错误声明 ReturnController 未定义,有人请告诉我遗漏的内容我的代码,我是AJS的新手。

    Angular JS服务     

    

AngularJS样本申请

<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>

0 个答案:

没有答案