angularjs - model is never updating inside controller -


here app.js

  .state('search', {       url: '/search',       templateurl: 'templates/search-pages/home.html',       controller: 'searchcontroller'   })      .state('search/search-form', {       url: '/search/search-form',       templateurl: 'templates/search-pages/search-form.html',       controller: 'searchcontroller'   })    .state('search/search-form-settings', {       url: '/search/search-form-settings',       templateurl: 'templates/search-pages/search-form-settings.html',       controller: 'searchcontroller'   })      $urlrouterprovider.otherwise('/search'); 

home.html

<ion-view> <ion-nav-buttons side="right">   <a class="button button-icon icon ion-android-search" href="#search/search-form"></a> </ion-nav-buttons>   <ion-content class="padding">             <div ng-repeat="data in searchresult">                 {{data.title}}         </div>        </ion-content> </ion-view> 

on clicking searh button below page opened.

searchform.html:

<ion-nav-buttons side="right">   <button class="button button-icon icon ion-android-done" ng-disabled="npubmusrlocform.form.$invalid"  ng-click="searchbytag()"></button>   </ion-nav-buttons> 

here searchcontrollet.js :

  $scope.searchresult = [{title:"this 1"},{title:"this 2"}];   alert("init");     $scope.searchbytag = function()     {      $scope.searchresult.push({title:"this 3"});     $scope.searchresult.push({title:"this 4"});     $state.go('search');     alert($scope.searchresult.length); 

in alert show lengh 4 in html page render {title:"this 1"},{title:"this 2"}

two things need fixed states , urls:

.state('search', {   url: '/search',   templateurl: 'templates/search-pages/home.html',   controller: 'searchcontroller' })    .state('search.search-form', {   url: '/search-form',   templateurl: 'templates/search-pages/search-form.html',   controller: 'searchcontroller' })  .state('search.search-form-settings', {   url: '/search-form-settings',   templateurl: 'templates/search-pages/search-form-settings.html',   controller: 'searchcontroller' })    $urlrouterprovider.otherwise('/search'); 

the states should in format 'parent.child' not 'parent/child'.

the urls relative parent url.

then html should like:

<ion-view>   <ion-nav-buttons side="right">     <a class="button button-icon icon ion-android-search" ui-sref="search.search-form"></a>   </ion-nav-buttons>   <ion-content class="padding">        <ui-view/>      <div ng-repeat="data in searchresult">             {{data.title}}     </div>        </ion-content> </ion-view> 

Comments