Angular:双字段数据绑定的问题

时间:2015-11-28 13:05:19

标签: angularjs ionic

我的离子应用程序中有这个单选按钮:

<ion-radio ng-model="data.sort" ng-value="['-timestamp','model']" ng-click="closeSortPopover();">Recent model (default)</ion-radio>

但是当我在控制器或视图中的其他位置将$scope.data.sort设置为['-timestamp','model']时,它不会自行检查。

请在此处查看codePen

1 个答案:

答案 0 :(得分:1)

如果我将数组包装到范围变量,它可以正常工作

<强> HTML

<ion-nav-view>
     <ion-view>
       <ion-content>

          <ion-radio ng-model="data.sort" ng-value="someValue" ng-click="closeSortPopover();">['-timestamp','model']</ion-radio>
          <ion-radio ng-model="data.sort" ng-value="'brand'"   ng-click="closeSortPopover()">Brand</ion-radio>

         <br/><br/>

         <button id="resetbutton" class="button icon-left ion-ios-reload button-dark" ng-click='data.sort=someValue;'>Set to data.sort to ['-timestamp','model']</button>

         <br/><br/>

         data.sort = {{data.sort}}
       </ion-content>
     </ion-view>  
</ion-nav-view>

<强>控制器

angular.module('ionicApp', ['ionic'])

.controller('MyCtrl', function($scope) {
  $scope.myTitle = 'This header hides the content below';
  $scope.someValue = ["-timestamp","model"];
  $scope.data={};
  $scope.data.sort = $scope.someValue;
});