View and navigation states and resolve/promise

Um developing an app with view navigation … but i have a problem transferring data … i think um doing something wrong … help please…

Everything works great but i can’t get the data to be viewed in the search-results.html as the cards are viewed empty like there is no attributes with these names…

am i missing something? THanks

///These are 2 states for example a search tab that includes all the criteria to filter the search///

.state('tab.search', {
                        url: "/search",
                        views: {
                            'search-tab':{
                                templateUrl: "search.html",
                                controller: 'SearchCtrl',
                                resolve: {
                                    loadData: searchCTRL.loadData
                                }
                            }
                        }
                    })

                    .state('tab.search-results', {
                        url: "/search/results",
                        views: {
                            'search-tab':{
                                templateUrl: "search-results.html",
                                controller: 'SearchResultsCtrl',
                                resolve: {
                                    loadData: searchResultsCTRL.loadresultsData
                                }
                            }
                        }
                    })

um having a controller for each page…

//////SEARCH RESULTS CTRL////////
        var searchResultsCTRL = premierApp.controller('SearchResultsCtrl', function($scope) {
            $scope.resultsJobs = searchResultsCTRL.resultsJobs;
          /// alerting the resultsJobs here works
            console.log('SearchResultsCtrl');
        })

        searchResultsCTRL.loadresultsData = function($q){
            var defer=$q.defer();

            var param=  // here are the params in JSON
            $.post("http://localhost:80080/?con=api&page=jobsFilter",param
                , function(results) {
                    searchResultsCTRL.resultsJobs=JSON.parse(results);

                    alert(JSON.stringify(searchResultsCTRL.resultsJobs));

                    // Data is viewed correctly

                    defer.resolve();
                })
                .error(function() {
                    alert("Connection Failed");
                });

            console.log('searchResultsCTRL.loadResultsData');
            return defer.promise;
        }

This is the script in the index.html file

<script id="search-results.html" type="text/ng-template" ng-controller="SearchResultsCtrl">
            <view title="'Search Results'" left-buttons="ion-android-arrow-back">
                <content
                        has-header="true"
                        has-footer="false"
                        has-tabs="true"
                        scroll="true"
                        padding="true"
                        on-refresh=""
                        has-subheader="true"
                        >


                    <!-- for pull to refresh -->
                    <refresher></refresher>

                    <!-- content -->

                    <div class="list card" ng-repeat="resultsJob in resultsJobs">
                        <div class="item item-avatar">
                            <img src="img/jobhunt.jpg">
                            <h2>{{resultsJobs.title}}</h2>
                            <p>{{resultsJob.country_title}}, {{resultsJob.city}} </p>
                        </div>

                        <div class="item item-body">
                            <p ng-bind-html="resultsJob.description" ng-click=''>
                            </p>
                        </div>

                        <a class="item item-icon-left energized" ng-click=''>
                            <i class="icon ion-more"></i>
                            <div class="col-offset-75">
                                Read more
                            </div>
                        </a>

                    </div>

                </content>
            </view>
        </script>

You’d really be better of taking that “loadData” stuff out of your controllers and put them in a service.

1 Like

Um working on that right now. Thanks @Calendee.
Does ionic has the load-more?? … i’ve tried the refresher (pull to refresh)… but i want to have load more at the end of my list to view more items…

Thanks

At the end of your list, just show a button or text and set ng-click="loadSomeMoreStuff(). Then, in your controller, do whatever you need to load more data.

Hi there, for me the resolver only works on the main tab controller, the specific tab controllers did not get the data injected.