ng-bind not updating after closing modal form

2019-07-08 11:18发布

I have a view with one list item. After user clicked on this item, the modal form show. When user change value and close modal, the item-not not updating.

View:

    <ion-view ng-controller="settingsController">
  <ion-content>

    <div class="list">
        <ion-item class="item-icon-left" ng-click="openLanguageModal()">
          <i class="icon ion-chatboxes"></i>
          {{'Language'| translate}}

          <span class="item-note">
            <div ng-bind="choice"></div>
          </span>
        </ion-item>

    </div>
  </ion-content>

  <script id="language-modal.html" type="text/ng-template">
    <div class="modal">
      <ion-header-bar>
      <!-- <button class="button button-full button-dark" ng-click="closeLanguageModal()">{{'Done' | translate}}</button> -->
      <button class="button button-clear button-positive pull-right" ng-click="closeLanguageModal()">
        {{'Done' | translate}}
      </button>
      </ion-header-bar>
      <ion-content>
        <ion-list>
          <ion-radio ng-model="choice" ng-value="'en'"> English </ion-radio>
          <ion-radio ng-model="choice" ng-value="'ru'"> Русский </ion-radio>
        </ion-list>
      </ion-content>
    </div>
  </script>

</ion-view>

Controller:

app.controller('settingsController', function($scope, $ionicModal) {

   $ionicModal.fromTemplateUrl('language-modal.html', {
     scope: $scope,
     animation: 'slide-in-up'
   }).then(function(modal) {
     $scope.languageModal = modal;
   })

   $scope.choice = "en";

   $scope.openLanguageModal = function() {
     $scope.languageModal.show();
   }

   $scope.closeLanguageModal = function() {
     $scope.languageModal.hide();
   };

   $scope.$on('$destroy', function() {
     $scope.languageModal.remove();
   });
});

I dont understand why the ng-bind didnt updates, help please

1条回答
家丑人穷心不美
2楼-- · 2019-07-08 11:40

Try to use:

$scope.model.choice = "en";

in a main Controller (so that all other view controllers could inheritate this info).

and in all view (settings and language-modal) modify to:

ng-model="model.choice"

due to prototypal inheritance...

Here it is a working demo: http://codepen.io/beaver71/pen/XXaROB

查看更多
登录 后发表回答