angular.js - angularjs 中ui-sref里的地址會(huì)和瀏覽器里的不一致
問題描述
我在angular里面使用了ui-router, 在a標(biāo)簽中使用了ui-sref,但是現(xiàn)在發(fā)現(xiàn)一個(gè)情況就是,有時(shí)候莫名其妙瀏覽器地址欄里的參數(shù)會(huì)和標(biāo)簽里寫的不一致,而且時(shí)好時(shí)壞,不知道問題出在哪里了。
點(diǎn)擊a標(biāo)簽,會(huì)跳轉(zhuǎn)到另一個(gè)視圖上去的。不知道這樣寫對不對,主要是這個(gè)現(xiàn)象會(huì)突然出現(xiàn),毫無規(guī)律可循,地址欄的變化都是靠ui-sref去改變的,也沒有使用別的東西去修改url。。
路由代碼
.state(’chschool’,{ url: ’/chschool’, views: {’’: { templateUrl: ’templates/chschool.html’ //總視圖 內(nèi)嵌了頂部和右側(cè)學(xué)校部分},’indexheader@chschool’:{ templateUrl: ’templates/indexheader.html’ //頂部},’itemcontent’:{ templateUrl: ’templates/schoolpart.html’ //學(xué)校部分} }}).state(’chschool.school’,{ //修改學(xué)校 用來局部刷新 學(xué)校部分 這里根據(jù)路由參數(shù) url: ’/school/{id}’, views: {’itemcontent’:{ templateUrl: ’templates/schoolpart.html’} }}).state(’chdorm’,{ //進(jìn)入樓棟的頁面 需要根據(jù)傳入的學(xué)校參數(shù)來獲取對應(yīng)的樓棟,這里就碰到了傳入的學(xué)校id會(huì)和schoolpart.html里面用ng-repeat循環(huán)出來的ui-sref中的參數(shù)不同 url: ’/chdorm/{id}’, views: {’’: { templateUrl: ’templates/chdorm.html’ } }})
html 部分 總視圖
<section ui-view='indexheader'></section><p ng-show='hidep' class='yo-container'> <p class='yo-xs-left'><p > <p ng-include='’templates/citypart.html’'></p> //城市</p> </p> <p class='yo-xs-right'><p class='yo-school'> <!--<p ng-include='’templates/schoolpart.html’'></p>--> <p ui-view='itemcontent'></p> //學(xué)校部分</p> </p></p>
citypart.html
<a ng-repeat='item in items' ui-sref='.school({id:item.ID})' ui-sref-active='yo-active'> {{item.cityname}}</a>
schoolpart.html
<p ng-controller='chschoolController'> <p ng-if='items.length==0'>團(tuán)隊(duì)招募,期待你的加入</p> <p ng-repeat='item in items track by $index' ng-cloak><a ui-sref='chdorm({id:item.ID})' ng-click='setItem($index)'>{{item.schName}}</a> </p></p>
問題解答
回答1:最好把壞的情況是什么樣式貼出來,題外話,你js可以稍微優(yōu)化
.state(’app.table.datatable’, { url: ’/datatable/:id’, templateUrl: function (stateParams) {console.log(stateParams);return ’resources/tpl/test/table_static.html’; }, resolve: {loadMyCtrl: [’$ocLazyLoad’, function ($ocLazyLoad) { return $ocLazyLoad.load(’resources/js/controllers/dataTableDemo.js’);}] } })回答2:
能放上出現(xiàn)錯(cuò)誤的截圖嗎?如果需要定位的話,可以在config里面監(jiān)聽路由切換事件$stateChangeStart,并查看路由變換記錄:
$rootScope.$on(’$stateChangeStart’, function(event, toState, toParams, fromState, fromParams){ console.info(fromState + '->' + toState, toParams, fromParams); })
相關(guān)文章:
1. mysql 查詢身份證號(hào)字段值有效的數(shù)據(jù)2. 視頻文件不能播放,怎么辦?3. node.js - nodejs開發(fā)中常用的連接mysql的庫4. python bottle跑起來以后,定時(shí)執(zhí)行的任務(wù)為什么每次都重復(fù)(多)執(zhí)行一次?5. mysql - 把一個(gè)表中的數(shù)據(jù)count更新到另一個(gè)表里?6. 請教使用PDO連接MSSQL數(shù)據(jù)庫插入是亂碼問題?7. mysql - 分庫分表、分區(qū)、讀寫分離 這些都是用在什么場景下 ,會(huì)帶來哪些效率或者其他方面的好處8. python - 爬蟲模擬登錄后,爬取csdn后臺(tái)文章列表遇到的問題9. visual-studio - Python OpenCV: 奇怪的自動(dòng)補(bǔ)全問題10. Python爬蟲如何爬取span和span中間的內(nèi)容并分別存入字典里?
