Javascript 爱奥尼亚应用程序-控制器$http
我在ionic中构建一个应用程序,我试图通过控制器将外部restful api数据导入视图,但我的控制器似乎有问题,因为没有任何东西被拉入 我的代码是:Javascript 爱奥尼亚应用程序-控制器$http,javascript,angularjs,ionic-framework,ionic,Javascript,Angularjs,Ionic Framework,Ionic,我在ionic中构建一个应用程序,我试图通过控制器将外部restful api数据导入视图,但我的控制器似乎有问题,因为没有任何东西被拉入 我的代码是: angular.module('starter',['ionic'])) .run(函数($ionicPlatform){ $ionicPlatform.ready(函数(){ //默认情况下隐藏附件栏(删除此选项可在键盘上方显示附件栏) //表格输入) if(window.cordova&&window.cordova.plugins.Ke
angular.module('starter',['ionic']))
.run(函数($ionicPlatform){
$ionicPlatform.ready(函数(){
//默认情况下隐藏附件栏(删除此选项可在键盘上方显示附件栏)
//表格输入)
if(window.cordova&&window.cordova.plugins.Keyboard){
插件键盘hideKeyboardAccessoryBar(真);
}
如果(窗口状态栏){
StatusBar.styleDefault();
}
});
})
.controller('myCtrl',函数($scope,$http){
$http.get('http://jsonplaceholder.typicode.com/posts)。然后(函数(结果){
$scope.posts=results.data.posts;
},函数(err){
console.error('ERR',ERR);
//err.status将包含状态代码
})
});代码>
{{post.title}
放置
Quisque quis sem是一个水平的地方,它是一只猫的交通工具。Mauris posuere,nisl vitae调味品luctus,tellus enim blandit orci,quis efficitur Nib libero eget dui。发酵木瓜的扫描电镜分子
解决方案:
$http.get('http://jsonplaceholder.typicode.com/posts')
.success(function(results){
$scope.posts = results.posts;
console.log($scope.posts);
});
您使用的是数据
,但结果中没有数据
。看看控制台,现在应该可以看到对象了
您在代码中犯了两个错误:
首先:在ng repeat中定义“item”后,应使用它绑定对象键“title”:
“item”现在保存着您的JSON密钥
如需更多帮助:我已获取了您提供的代码并使其在plunk上工作,请在以下url上查看:
请与我联系以获得更多帮助。谢谢你为什么不使用.success?请你详细说明一下,我对angular JS很陌生?我如何添加它以便你可以运行有问题的代码?你把它放在哪里了,因为这对我不起作用?更新:html部分有点错误,它需要读:{{item.title}而不是{post.title}请你把我的答案标记为正确,然后投票表决。不客气:D
ng-repeat='item in posts'
<h2>{{item.title}}</h2>
$scope.posts = results.data