我用AngularJS创建了一个单页房地产列表web应用程序,决定使用/$http服务提供数据,但没有成功.有人知道为什

I have a single page real estate listing web app I created with AngularJS, decided to serve up data w/$http service, didn't work. Can anybody see why?

本文关键字:服务 提供数据 http 成功 决定 AngularJS 创建 一个 应用程序 我用 web      更新时间:2023-09-26

下面是三个文件,我认为这是问题的根源。我知道我可能已经使用POST, GET, PUT, DELETE,但我故意尝试使用$http。

mansionsController.js文件:

angular
    .module('ngMansions')
    .controller('mansionsController', function($scope, mansionsFactory) {
            $scope.mansions;
            mansionsFactory.getMansions().success(function(data) {
            $scope.mansions = data;
            }).error(function(error) {
                console.log(error);
            });      
});

mansionsFactory.js文件:

angular
    .module('ngMansions')
    .factory('mansionsFactory', function($http) {

    function getMansions() {
        return $http.get('data/data.json');
    }
    return {
        getMansions: getMansions
    }
});

数据。json文件:

 [
        {
            "type": "Condo",
            "price": 220000,
            "address": "214 Grove Street",
            "description": "Excellent place, really nice view!"
        },
        {
            "type": "House",
            "price": 410500,
            "address": "7823 Winding Way",
            "description": "Beautiful home with lots of space for a large family."
        },
        {
            "type": "Duplex",
            "price": 395000,
            "address": "834 River Lane",
            "description": "Great neighborhood and lot's of nice green space."
        }
    ]; 

在json文件的方括号末尾有一个分号。这些小细节总是让我不知所措。谢谢大家的努力。