angular : $location & $state(UI router)的关系

次序:angular 的 location会先跑

$rootScope.$on("$locationChangeStart", function (scope, newUrl, oldUrl) {
    log("$locationChangeStart from " + oldUrl)
    log("$locationChangeStart to " + newUrl)
});

接着是 ui router $state

$rootScope.$on("$stateChangeStart", function (event, toState, toParams, fromState, fromParams) {
                log("$stateChangeStart from " + fromState.name)
                log("$stateChangeStart to " + toState.name)
});

log出来的结果是$stateChangeStart 的fromState 是空,这是router UI 的机制,一开始没有state 去到state是会detect到

 

router UI $state是监听 angular 的$location,如果之前的url 或 state是一样的就不会触发。

$location.hash()是用digest换url的

posted @ 2015-10-19 11:23  泉油  阅读(444)  评论(0编辑  收藏  举报
Web Design Johor Bahru Malaysia - Stooges