ng-bind not updating after closing modal form

允我心安 提交于 2019-12-10 23:42:17

问题


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:


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



来源:https://stackoverflow.com/questions/34767304/ng-bind-not-updating-after-closing-modal-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!