角$ HTTP GETHTTP、GET

由网友(靜如·水)分享简介:我想在angularJS Ajax调用,JSON是加载,但数据不填充。 I want to make an ajax call in angularJS, JSON is loading but the data is not populating. demoApp.controller('MainControlle...

我想在angularJS Ajax调用,JSON是加载,但数据不填充。

I want to make an ajax call in angularJS, JSON is loading but the data is not populating.

    demoApp.controller('MainController', function($scope, GetData) {

        $scope.data = null;
        GetData.getDoctors(function(dataResponse) {
            $scope.data = dataResponse;
        });

    });


    demoApp.factory('GetData', function($http) {

        var doctors = [];
        this.getDoctors = function(callBack) {
            $http({

                method: 'GET',
                url: 'json/location.json'
            }).
            success(function(data) {
                callBack(data);
            }).
            error(function(data) {
                alert("Error");
            });

        }
    });

即使是JSON文件没有加载..what是在code中的错误?

Even the Json file is not loading ..what is the error in the code?

推荐答案

角工厂应该返回的东西。

Angular factory should return something.

尝试

demoApp.factory('GetData', function($http) {
    var methods = {};

    methods.getDoctors = function(callBack) {
        $http({
            method: 'GET',
            url: 'json/location.json'
        }).
        success(function(data) {
            callBack(data);
        }).
        error(function(data) {
            alert("Error");
        });
    };

    return methods;
});
阅读全文

相关推荐

最新文章