我尝试使用ionic frameworkAngularjs构建新的APP。

现在我的问题是我无法从控制器显示结果。我尝试在浏览器中打开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>


和控制器

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('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>


它适用于我的测试

javascript - Angular.js:从控件打印对象到 ionic  View-LMLPHP

07-24 17:49