【发布时间】:2018-03-17 03:16:03
【问题描述】:
我正在使用 angularjs:1.6.5 和 ui-router:1.0.3
主 html:
<div ng-app="MusicApp" ng-controller="AppCtrl">
<div ng-include="plugins_url + 'templates/sideMenu.html'"></div>
<md-content ng-controller="playlistController">
<div ng-include="plugins_url + 'templates/header.html'"></div>
<div class="all_content" >
<div ng-show="!isHome">
<div ui-view id="other_views" ></div>
</div>
<div ng-include="plugins_url + 'templates/main.html'" ng-show="isHome"></div>
</div>
</md-content>
[etc]
来自 sideMenu.html 的内容:
<li><a ui-sref="charter">Home</a></li>
<li><a ui-sref="charter.test">Test</a></li>
我的问题是 stateChange 基本上没有一个提供工作,我尝试过:$stateChangeError、$stateChangeCancel、$stateChangeStart、$stateChangeSuccess,如下所示:
$rootScope.$on('$stateChangeSuccess', function (event, toState, toParams, fromState) {
console.log('called')
})
但它从未被调用...尝试将它放在 .config 中,在每个控制器中,用 $scope 和/或 $rootScope 尝试过,但是 nada。
奇怪的是,我在控制台中将此视为警告:
angular.min.js?1507208413&ver=4.8.2:123 $route service is not available. Make sure you have included ng-route in your application dependencies.
所以它不知何故无法识别 ui.router,它当然是作为文件加载的,并作为 'ui.router' 插入到依赖项中。最奇怪的部分是,ui-sref 正在工作,正如您在 sideMenu.html 中看到的那样......
是否可能存在兼容性问题...某处?
感谢任何帮助!
编辑: 我尝试过使用 ui.router 0.4.3 及旧版本,但它甚至无法启动应用程序...
【问题讨论】:
标签: angularjs angular-ui-router