ng-view viewContentLoaded

283 views
Skip to first unread message

Grina Zh

unread,
May 20, 2013, 11:25:13 AM5/20/13
to ang...@googlegroups.com
I use  ng-view to display results of search in DB.

Can anyone help me why do not update the data in ng-view?

In main template:


    <div ng-controller="searchCriterias">

        <fieldset>
            Search:
            <input type="text" ng-model="ssearch.title" />
        </fieldset>
        <fieldset>
            <button type="text" ng-click="startSearch()">Search</button>

        </fieldset>

    </div>

    <div ng-controller="AppCTRL">
         <div ng-view="searchResults"></div>
    </div>


In .js I have:
var app = angular.module('sh_l_searchproduct', ['ngGrid','ui.bootstrap']);

app.config(function($routeProvider){
    $routeProvider.when('/',
        {
            templateUrl: "one_prod_template.html",
            controller: "AppCTRL"
        }
        ).
        otherwise({
            redirectTo: '/'
        });

})



app.controller("AppCTRL",function($scope, $http){

    var $loading = $('#loading').center();
    $loading.hide();

    $scope.getPagedDataAsync = function (pageSize, page) {
        setTimeout(function () {
            $('#loading').show();

            searchScope = angular.element('[ng-controller=searchCriterias]').scope()

            $http.post('services/serviceESProductsSearch.php', {"pageSize": pageSize, "page" : page, "criterias": searchScope.ssearch}).success(function (largeLoad) {
                $('#loading').hide();

                $scope.items = largeLoad.records;

                var numFiles = angular.element('[ng-view=searchResults]').scope().items.length;

                console.log(numFiles);

                $scope.$on('$viewContentLoaded', function () {
                    console.log("$viewContentLoaded");
                });

            });
        }, 100);
    };


    $scope.firstDataRetrieve = true;

    $scope.getPagedDataAsync(25, 1);

    $scope.model = {
        message: "Search Products!!"

    }
})

app.controller('searchCriterias', function($scope, $http) {

    $scope.startSearch = function () {
        gridscope = angular.element('[ng-controller=AppCTRL]').scope();
        gridscope.getPagedDataAsync(25, 1);
    }

});


The search results are displayed when the first page is loaded.
But when I click on the "Search"-button right data received, but  old data is diplayed.

Can anyone help me why do not update the data in ng-view?


Thanks!

Grant Rettke

unread,
May 20, 2013, 4:07:03 PM5/20/13
to ang...@googlegroups.com
On Mon, May 20, 2013 at 10:25 AM, Grina Zh <guc...@gmail.com> wrote:
> Can anyone help me why do not update the data in ng-view?

Maybe try plunker instead.
Reply all
Reply to author
Forward
0 new messages