Search code examples
angularjsviewcontrollersmart-table

Angular view not updating controller variable


My angular view is not updating after changing a value in the controller via a partial. When I do a console.log it logs the changed values.

TestController

$scope.testitem = 0;

$scope.updatePagination = function(page, lastPage) {
    console.log('Test ', + page + " " + lastPage); //works
    $scope.testitem = page; //doesnt work
};

View

p(ng-model="testitem") {{testitem}} test
div(st-pagination="", st-items-by-page="displayAmount", st-displayed-pages="7", class="pagination" st-template="/partials/pagination.custom.html")

pagination.custom.html

nav(ng-if='pages.length >= 2')
ul.pagination
    li.non-clickable(ng-repeat="page in pages", ng-class="{active: page==currentPage}", ng-controller="controller")
        a( ng-click='selectPage(page); updatePagination(page, numPages)') {{page}}

Solution

  • Try the below, you may need to tell the view that there has been an update to the scope.

    $scope.apply(function(){
        $scope.testitem = page; //doesnt work
    });