javascript - Angular js : Print object from control to view with ionic

标签 javascript angularjs ionic-framework

我尝试使用ionic框架Angularjs构建新的应用程序。

现在我的问题是我无法显示 Controller 的结果以供查看。我尝试在浏览器中打开 console.log(allposts);,我们显示的结果很好。

但鉴于它没有显示任何东西

allpost.html

<dive class="item itemfull" ng-repeat="post in allpost">
<div class="item item-body">
<div>{{ post.title }}
<div class="title-news"><div class="title" ng-bind-html="post.content"></div></div>
</div>
</div>
</div>

和 Controller

myApp.controller('allpost', function($scope , $http , $stateParams , Allposts) {
        var id = $stateParams.id;
        $scope.post = Allposts.GetAllposts(id);
    });

myApp.factory('Allposts',['$http', '$q',function($http,$q){
                var allposts = [];
                var pages = null;
                return {

                GetAllposts: function (id) {
                    return $http.get("http://kotshgfx.info/azkarserv/?json=get_category_posts&id="+id+"&status=publish",{params: null}).then(function (response) {
                       items = response.data.posts;
                        allposts = items;
                        console.log(allposts); 
                        return items;
                        $ionicLoading.hide();
                    });
                }
                }
        }]);

哪里出错了?

最佳答案

尝试在js文件中的 Controller 和工厂中更改这样的代码

.controller('allpost', function ($scope, $http, $stateParams, Allposts) {
    var id = $stateParams.id;
    Allposts.GetAllposts(id).then(
        function (response) {
            $scope.allPosts = response.data.posts;
        });

})

.factory('Allposts', ['$http', '$q', function ($http, $q) {
    return {

        GetAllposts: function (id) {
            return $http.get("http://kotshgfx.info/azkarserv/?json=get_category_posts&id=" +
                id + "&status=publish");

        }
    }
}]);

html 文件

 <div class="item itemfull" ng-repeat="post in allPosts">
        <div class="item item-body">
            <div>{{ post.title }}
                <div class="title-news">
                    <div class="title" ng-bind-html="post.content"></div>
                </div>
            </div>
        </div>
    </div>

它适用于我的测试

Result of test

关于javascript - Angular js : Print object from control to view with ionic,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32328450/

相关文章:

javascript - 只有 AngularJS 页面上的最后一个指令保持其绑定(bind)

javascript - 哪种方式绑定(bind)到动态单选按钮更好?

javascript - AngularJS - 用 promise 处理错误

javascript - 如何使用 Cordova 在缩略图中显示缩小尺寸的图像

android - cordova-plugin-inapppurchase 错误 : package com. android.vending.billing 不存在

javascript - 具有可变宽度的水平居中图像

javascript - 如何使用 done() 或 next() 将参数传递给下游函数

javascript - node.js 将表情符号转换为 unicode 或其他?

javascript - jQuery Form to Wizard,隐藏某个步骤

android - 是否可以以编程方式重新启动 Ionic 应用程序?