角度1&在radiobutton选择后,ionic1更新ui-ref

时间:2016-07-17 09:18:43

标签: angularjs ionic-framework

我有点失落。在用户单击其中一个单选按钮后,我尝试更新按钮的ui-refui-ref正确更新,但自动生成的href保持不变。我做错了什么?

视图中的代码:

<div ng-controller="radiotCtrl">
    <div class="list" >
            <ion-radio ng-repeat="item in radiotList"
                     ng-value="item.value"
                     ng-model="data.radiot">
            {{ item.text }}
          </ion-radio>
        </div>
      <div  ui-sref='{{ data.radiot }}'>  <a  id="button14" class=" button button-positive  button-block button-outline ">Next</a></div>
   </div>

和控制器:

.controller('radiotCtrl', function($scope) {

    $scope.radiotList = [
        { text: "Selection 1", value: 'mynav.sele1' },
        { text: "Selection 2", value: 'mynav.sele2' },

    ];

    $scope.data = {
        radiot: 'mynav.sele1'
    };

});

2 个答案:

答案 0 :(得分:0)

您应该将ui-sref放在锚点(a)标记上,以便通过评估提供给它的状态生成正确的href

<div>  
   <a ui-sref='{{ data.radiot }}' id="button14" 
     class=" button button-positive  button-block button-outline ">
       Next
   </a>
</div>

答案 1 :(得分:0)

ui-sref 不支持双向数据绑定。这是关于github上的这个主题的讨论:https://github.com/angular-ui/ui-router/issues/395

对我来说,一个简单而有效的解决方案是使用ng-click代替:

视图中的代码:

 <div ng-controller="RadioBuCtrl">
<form class="list ">
<ion-radio ng-model="user.answer" ng-value="'mynav.optionone'">Option 1</ion-radio>
<ion-radio ng-model="user.answer" ng-value="'mynav.optiontwo'">Option 2</ion-radio>
</form>
<a ng-click="submitAnswer(user)" class="button button-positive">Next</a>
</div>

和控制器:

.controller('RadioBuCtrl', function($scope, $state) {
  $scope.submitAnswer=function(user){
 $state.go(user.answer);
 }
});