我用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?
下面是三个文件,我认为这是问题的根源。我知道我可能已经使用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文件的方括号末尾有一个分号。这些小细节总是让我不知所措。谢谢大家的努力。
相关文章:
- AngularJS-需要在index.html页面中访问来自服务的数据
- 函数jquery.html()不提供数据属性集值
- SqlStorage Ionic 2作为服务/提供程序
- 如何在公共js模块中从web服务返回数据
- 使用 javascript 从本地主机服务获取数据
- 如何在控制器之间共享来自休息服务的数据
- angularjs服务生成数据后,我该如何停止它
- md自动完成don't等待来自服务的数据.如何解决
- Oracle Jet未显示来自web服务的数据
- 以编程方式为传单地图上的标记提供数据属性
- 如何使用Angular 2服务提供包含指向另一个资源的链接/ids的资源集合
- 使用JSON从web服务获取数据
- 使用$http服务将数据发布到本地 json 文件时未发现错误
- 无法获取使用 HTML 简单登录到 PHP Web 服务的数据
- 从服务提供商 IP 地址获取设备 IP 地址
- (IONIC)错误: [$injector:unpr] 未知提供程序: 数据服务提供程序 <- 数据服务<- 身份验证控
- 服务没有从.json文件中向控制器提供数据
- 使用Angular服务提供数据
- 我用AngularJS创建了一个单页房地产列表web应用程序,决定使用/$http服务提供数据,但没有成功.有人知道为什
- AngularJS:选项卡窗格的HTML标记各不相同,我希望它们是动态创建的,并填充由工厂服务提供的数据