angularjs – 下拉列表中的Angular ui-sref不起作用
发布时间:2020-12-17 17:20:51 所属栏目:安全 来源:网络整理
导读:我有一个带路由的角度应用程序.我有一个下拉选择定义如下: select class="form-control" id="transactiontype" ng-model="tt" optiona ui-sref="cash"Cash/a/option optiona ui-sref="cheque"Cheque/a/option optiona ui-sref="debitcard"Debit/a/option op
我有一个带路由的角度应用程序.我有一个下拉选择定义如下:
<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标签变化的最佳选择.那一刻我忘记了.所以请参考他的回答.美好的一天. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |