angular.js - angularjs 使用modal 選中modal中的li列表后傳值
問題描述
如上圖 我想做一個這種界面的效果 選中列表中的值 除了選中貓糧是跳轉,其他的選項均在本頁面異步刷新相應的數據,因為使用了ui-bs里面的modal
目前想的是兩種方式:1.選中后改變相應的路由參數 再次$http請求2.直接跳轉到相應的路由+參數的頁面 但是第2種如果在本頁面多次選擇的話 到最后點擊返回按鈕就很麻煩請教一下這個應該怎么做?
// 資產選擇模態框$scope.items = [ {assetName: ’全部理財’, type: ’0’, holdType: ’0’, redeemType: ’0’}, {assetName: ’活期貓’, type: ’7’, holdType: ’4’, redeemType: ’4’}, {assetName: ’月月漲’, type: ’1’, holdType: ’5’, redeemType: ’5’}, {assetName: ’季度喵’, type: ’4’, holdType: ’3’, redeemType: ’3’}, {assetName: ’半年喵’, type: ’5’, holdType: ’6’, redeemType: ’6’}, {assetName: ’九九喵’, type: ’6’, holdType: ’9’, redeemType: ’9’}, {assetName: ’年豐收’, type: ’2’, holdType: ’12’, redeemType: ’12’}, {assetName: ’發財喵’, type: ’8’, holdType: ’1’, redeemType: ’1’}, {assetName: ’貓糧’, type: ’3’, holdType: ’7’, redeemType: ’7’}];$scope.openModal = function (size) { var triangle = jQuery(’.triangle’); //這里很關鍵,是打開模態框的過程 var modalInstance = $uibModal.open({templateUrl: ’myModalContent.html’,//模態框的頁面內容,這里的url是可以自己定義的,也就意味著什么都可以寫controller: ’ModalInstanceCtrl’,//這是模態框的控制器,是用來控制模態框的size: size,//模態框的大小尺寸resolve: {//這是一個入參,這個很重要,它可以把主控制器中的參數傳到模態框控制器中 items: function () {//items是一個回調函數return $scope.items;//這個值會被模態框的控制器獲取到 }} }); modalInstance.opened.then(function () {triangle.css({transform: ’rotate(270deg)’}) }); modalInstance.result.then(function (selectedItem) {//這是一個接收模態框返回值的函數// $scope.selected = selectedItem;//模態框的返回值console.log(selectedItem);console.log($scope.selected); }, function () {$log.info(’Modal dismissed at: ’ + new Date());triangle.css({transform: ’rotate(360deg)’}) });}; .controller(’ModalInstanceCtrl’, function ($scope,$http, $uibModalInstance,$location,items) {//這是模態框的控制器,記住$uibModalInstance這個是用來調用函數將模態框內的數據傳到外層控制器中的,items則上面所說的入參函數,它可以獲取到外層主控制器的參數$scope.items = items;//這里就可以去外層主控制器的數據了var triangle = jQuery(’.triangle’);$scope.selected = { item: $scope.items[0]};$scope.selasset = function (type,holdType,redeemType) { if(type == ’3’){$location.path(’/grain’) }else {// $location.path(’/asset/’+type+’/’+holdType+’/’+redeemType); } $uibModalInstance.close($scope.selected.item); // $uibModalInstance.close(); triangle.css({transform: ’rotate(360deg)’})};$scope.cancelModal = function () { //dismiss也是在模態框關閉的時候進行調用,而它返回的是一個reason $uibModalInstance.dismiss(’cancel’); triangle.css({transform: ’rotate(360deg)’})}; })
上面沒有controller的是當前頁面的open modal動畫及數據下面是modal的controller
問題解答
回答1:方法2+location.path().replace
相關文章:
1. python - beautifulsoup獲取網頁內容的問題2. Docker for Mac 創建的dnsmasq容器連不上/不工作的問題3. docker鏡像push報錯4. docker - 如何修改運行中容器的配置5. docker-machine添加一個已有的docker主機問題6. fragment - android webView 返回后怎么禁止重新渲染?7. dockerfile - [docker build image失敗- npm install]8. angular.js - 在終端中用yeoman啟用angular-generator報錯,求解?9. Android "1"=="1" 到底是true還是false10. android studio總是在processes running好久
