angular.js - angularjs 使用modal 選中modal中的li列表后傳值
問題描述
如上圖 我想做一個這種界面的效果 選中列表中的值 除了選中貓糧是跳轉(zhuǎn),其他的選項均在本頁面異步刷新相應(yīng)的數(shù)據(jù),因為使用了ui-bs里面的modal
目前想的是兩種方式:1.選中后改變相應(yīng)的路由參數(shù) 再次$http請求2.直接跳轉(zhuǎn)到相應(yīng)的路由+參數(shù)的頁面 但是第2種如果在本頁面多次選擇的話 到最后點擊返回按鈕就很麻煩請教一下這個應(yīng)該怎么做?
// 資產(chǎn)選擇模態(tài)框$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: ’發(fā)財喵’, type: ’8’, holdType: ’1’, redeemType: ’1’}, {assetName: ’貓糧’, type: ’3’, holdType: ’7’, redeemType: ’7’}];$scope.openModal = function (size) { var triangle = jQuery(’.triangle’); //這里很關(guān)鍵,是打開模態(tài)框的過程 var modalInstance = $uibModal.open({templateUrl: ’myModalContent.html’,//模態(tài)框的頁面內(nèi)容,這里的url是可以自己定義的,也就意味著什么都可以寫controller: ’ModalInstanceCtrl’,//這是模態(tài)框的控制器,是用來控制模態(tài)框的size: size,//模態(tài)框的大小尺寸resolve: {//這是一個入?yún)?這個很重要,它可以把主控制器中的參數(shù)傳到模態(tài)框控制器中 items: function () {//items是一個回調(diào)函數(shù)return $scope.items;//這個值會被模態(tài)框的控制器獲取到 }} }); modalInstance.opened.then(function () {triangle.css({transform: ’rotate(270deg)’}) }); modalInstance.result.then(function (selectedItem) {//這是一個接收模態(tài)框返回值的函數(shù)// $scope.selected = selectedItem;//模態(tài)框的返回值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) {//這是模態(tài)框的控制器,記住$uibModalInstance這個是用來調(diào)用函數(shù)將模態(tài)框內(nèi)的數(shù)據(jù)傳到外層控制器中的,items則上面所說的入?yún)⒑瘮?shù),它可以獲取到外層主控制器的參數(shù)$scope.items = items;//這里就可以去外層主控制器的數(shù)據(jù)了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也是在模態(tài)框關(guān)閉的時候進行調(diào)用,而它返回的是一個reason $uibModalInstance.dismiss(’cancel’); triangle.css({transform: ’rotate(360deg)’})}; })
上面沒有controller的是當前頁面的open modal動畫及數(shù)據(jù)下面是modal的controller
問題解答
回答1:方法2+location.path().replace
相關(guān)文章:
1. mac OSX10.12.4 (16E195)下Mysql 5.7.18找不到配置文件my.cnf2. mysql - 數(shù)據(jù)庫表中,兩個表互為外鍵參考如何解決3. 在mybatis使用mysql的ON DUPLICATE KEY UPDATE語法實現(xiàn)存在即更新應(yīng)該使用哪個標簽?4. mysql - 數(shù)據(jù)庫建字段,默認值空和empty string有什么區(qū)別 1105. mysql儲存json錯誤6. sql語句 - 如何在mysql中批量添加用戶?7. mysql - 表名稱前綴到底有啥用?8. php - 公眾號文章底部的小程序二維碼如何統(tǒng)計?9. Navicat for mysql 中以json格式儲存的數(shù)據(jù)存在大量反斜杠,如何去除?10. mysql - 怎么生成這個sql表?
