离子/角应用不读通过api JSON数据 [英] Ionic/Angular App not reading json data from api
问题描述
我正在写一个应用离子从Web API我asp.net MVC4创建读取一些数据。离子应用程序读取数据就好了,当我收留了它我的本地机器上,但是当我尝试当它在Azure上公布从Web API读取角度工厂不返回任何东西。是否有任何合乎逻辑的理由,当它发布到Azure的这是行不通的?
JSON字符串是在同一个既当我访问本地和蔚蓝的网站。
[{ID:1,名称:花火,时代周刊:2015-11-30T21:00:00,评论:要还有8:00},
{ID:2,姓名:理发,时代周刊:2015-11-30T21:00:00,评论:以8:00将有}]
下面是code为我的角度厂
.factory('EventsFactory',['$ HTTP',函数($ HTTP){
返回$ http.get('这里的WebAPI链接)
.success(功能(数据){
返回的数据;
})
.error(功能(错误){
返回ERR;
});
}])
下面是code为我的角度控制器
.controller('EventCtrl',['$范围,EventsFactory',函数($范围,EventsFactory){
EventsFactory.success(功能(数据){
$ scope.activities =数据;
});
}])
下面是code对我的看法。
< DIV CLASS =列表牌NG-控制器=EventCtrl>
< DIV CLASS =项项除法>近期活动< / DIV>
< DIV CLASS =项项体NG重复=活动活动>
< DIV> {{activity.Name}}< / DIV>
< / DIV>
< / DIV>
在你的控制器,你需要使用然后
EventsFactory()。然后(功能(数据){
$ scope.activites =数据;
})
I'm writing an Ionic app to read some data from a web API I created with asp.net MVC4. The Ionic app reads the data just fine when I'm hosting it on my local machine but the angular factory does not return anything when I try to read from the web API when it is published on Azure. Is there any logical reason why this wouldn't work when it is published to Azure?
The json string is the same on both when i visit the local and azure site.
[{"ID":1,"Name":"Fireworks","Time":"2015-11-30T21:00:00","Comments":"Be there by 8:00"},
{"ID":2,"Name":"Haircut","Time":"2015-11-30T21:00:00","Comments":"Be there by 8:00"}]
Here is the code for my angular factory
.factory('EventsFactory', ['$http', function($http) {
return $http.get('webAPI link here')
.success(function(data) {
return data;
})
.error(function(err) {
return err;
});
}])
Here is the code for my angular controller
.controller('EventCtrl', ['$scope', 'EventsFactory', function($scope, EventsFactory) {
EventsFactory.success(function(data){
$scope.activities = data;
});
}])
Here is the code for my view
<div class="list card" ng-controller="EventCtrl">
<div class="item item-divider">Upcoming Events</div>
<div class="item item-body" ng-repeat="activity in activities">
<div>{{activity.Name}}</div>
</div>
</div>
In your controller, you need to use then
EventsFactory().then(function(data){
$scope.activites = data;
})
这篇关于离子/角应用不读通过api JSON数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!