我在我的应用程序中遇到问题,当我在本地主机中运行应用程序时它没有问题,我可以看到频道列表但是当我尝试通过物理设备测试应用程序时它没有显示任何内容。我认为问题来自我用来通过http发送json数据的方法。
(function () {
'use strict';
angular.module('testApp').controller('ChannelCtrl', ['$state', 'testApi', ChannelCtrl]);
function ChannelCtrl($state, testApi) {
var vm = this;
myscreenApi.getChannels().then(function(data){
vm.channels = data;
});
vm.selectLeague = function(id){
testApi.setChannelId(id);
$state.go("app.video");
}
};
})();
这是我获取通道数据的功能
function getChannels() {
var deferred = $q.defer(),
cacheKey = "leagues",
ChannelsData = null;
if (ChannelsData) {
console.log("Found data inside cache", ChannelsData);
deferred.resolve(ChannelsData);
$window.alert("From Cache");
} else {
$http.get("http://example.com/api/videos/getchannels")
.success(function(data) {
console.log("Received data via HTTP");
self.leaguesCache.put(cacheKey, data);
$window.alert("From HTTP");
deferred.resolve(data);
})
.error(function(dataerr) {
console.log("Error while making HTTP call.");
$window.alert("Error baba daram " + dataerr);
deferred.reject();
});
}
return deferred.promise;
}
当我用JSON.parse()发送数据时,它工作正常。
vm.channels = JSON.parse('[{"Name":"MyScreen News","ID":46,"Thumbnail":"CB46.jpg","Videos":null}]');
总的来说,我使用了由JSON发送数据的ASP.NET Web API。该应用程序在我们的桌面上运行良好,但运行的应用程序无法从我们的主机检索数据。而且,当我直接在程序中注入数据时,它可以在两个平台上工作。此外,离子配置文件如下所示:
<content src="index.html"/>
<access origin="*"/>
<preference name="webviewbounce" value="false"/>
<preference name="UIWebViewBounce" value="false"/>
<preference name="DisallowOverscroll" value="true"/>
<preference name="BackupWebStorage" value="none"/>
<feature name="StatusBar">
<param name="ios-package" value="CDVStatusBar" onload="true"/>
</feature>
就这样。 ;)