我的离子应用程序中有这个单选按钮:
<ion-radio ng-model="data.sort" ng-value="['-timestamp','model']" ng-click="closeSortPopover();">Recent model (default)</ion-radio>
但是当我在控制器或视图中的其他位置将$scope.data.sort
设置为['-timestamp','model']
时,它不会自行检查。
请在此处查看codePen。
答案 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;
});