2

我有一个列表项的视图。用户点击此项目后,将显示模态表单。当用户更改值并关闭模式时,项目不会更新。

看法:

    <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>

控制器:

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();
   });
});

我不明白为什么 ng-bind 没有更新,请帮忙

4

1 回答 1

1

尝试使用:

$scope.model.choice = "en";

在主控制器中(以便所有其他视图控制器可以继承此信息)。

并在所有视图(设置和语言模式)中修改为:

ng-model="model.choice"

由于原型继承......

这是一个工作演示:http ://codepen.io/beaver71/pen/XXaROB

于 2016-01-13T13:10:54.557 回答