angularjs – 下拉列表中的Angular ui-sref不起作用

前端之家收集整理的这篇文章主要介绍了angularjs – 下拉列表中的Angular ui-sref不起作用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个带路由的角度应用程序.我有一个下拉选择定义如下:

<select class="form-control" id="transactiontype" ng-model="tt">
    <option><a ui-sref="cash">Cash</a></option>
    <option><a ui-sref="cheque">Cheque</a></option>
    <option><a ui-sref="debitcard">Debit</a></option>
    <option><a ui-sref="creditcard">Credit</a></option>
</select>

当我选择其中一个下拉列表时,它不会加载我引用的视图.我哪里错了?我也试过这个:

<option ui-sref="creditcard">Credit</option>

解决方法

考虑使用ng-options代替:

myApp.controller('MainController',['$scope','$state',function($scope,$state) {    
$scope.options = [
  { label: 'Cash',value: 'cash' },{ label: 'Cheque',value: 'cheque' },{ label: 'Debit',value: 'debit' },{ label: 'Credit',value: 'credit' }
];
$scope.$watch('tt',function(value) {
  if(value) {
    $state.go(value);
  }
});
}]);

HTML:

<div ng-controller="MainController">
  <select class="form-control" id="transactiontype" ng-model="tt" ng-options="opt.value as opt.label for opt in options">
  </select>
</div>

编辑:同意@Likwid_T所说的,我认为ng-change是检测select标签变化的最佳选择.那一刻我忘记了.所以请参考他的回答.美好的一天.

猜你在找的Angularjs相关文章