Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 49184

Ng-repeat doesn't always update when $scope is updated

$
0
0

@andyd94 wrote:

Hi all,

I'm having a slight issue with Ng-repeat. I have two views, the first one (Search) has a button which when clicked will add an item to $scope.results1 and then take the user to the other view (Results) where the ng-repeat is.

When I click the button and the results page comes up, only "1" is displayed. However, if I call the test function straight away in the controller, I get taken to the Results page and both "1" and "2" are displayed. In both cases, the console log shows that the array results1 contains 2 items.

What am I doing wrong?

Button in Search View :

<button class="button-full" id="find" ng-click="test();">Find</button>

SearchController:

 $scope.test = function(){
    $scope.results1.push(2);
    console.log("pushed 2");
    console.log($scope.results1);
    $state.go("tab.results");
  };

Results view:

  <ion-content ng-controller="SearchController">
    <body>
      <div id="results">
      <div class="list" id="search-items">
        <div ng-repeat="item in results1">
          {{item}}
        </div>
      </div>
    </div>
    </body>
  </ion-content>

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 49184

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>