AngularJS和UI路由器:为什么$state.go()和$location.path()在交互式控制台中不起作用
AngularJS & UI Router : Why do $state.go() and $location.path() not work in interactive console?
请参阅此 plunker : https://run.plnkr.co/mTN6nIsUkxFtiZLx/#/state1
https://plnkr.co/edit/KYQG3OMPoCthEDcus12Y?p=info
它基本上是 UI 路由器文档中提供的演示代码。为了以编程方式测试状态之间的导航,我制作了使用 $state.go(stateName)
和 $location.path(stateUrl)
的控制器函数,它们都可以正常工作。
控制器的代码:
myApp.controller('mainController', ['$scope', '$state', '$location', function($scope, $state, $location) {
$scope.usingState = function() {
console.log('usingState() called');
$state.go('state2');
};
$scope.usingLocation = function() {
console.log('usingLocation() called');
$location.path('/state2');
};
}]);
但是,在交互式控制台(开发人员工具(中,它不起作用。如果我执行以下操作:
$state = angular.element(document).injector().get('$state');
$state.go('state2');
或
$location = angular.element(document).injector().get('$location');
$location.path('/state2');
什么也没发生。为什么?
我希望能够在交互式控制台中进行快速测试...
您提到的上述代码似乎可以在控制台上运行。在 plunker 中,您无法从文档中获取injector
因为 plunker 在加载角度的<iframe>
内运行代码。
要测试功能,请打开 UI 路由器示例应用程序。 在控制台中输入以下代码并观察状态转换:
angular.element(document).injector().get('$state').go('about');
更新:
在您提供的 plunker 中,我将角度版本 1.1.5 更改为 1.2.0(1.1.5 之后发布的版本(,一切似乎都正常。以下是 1.2.0-rc.3 和 1.2.0 的更改日志,它们可能会帮助您追踪为什么它在以前的版本中不起作用。
更新了普伦克。希望这有帮助!
相关文章:
- 正在使用$location.path(.)路由ng视图
- RubyonRails——构建交互式接口应该朝哪个方向发展
- gulp Iconify任务抛出错误TypeError:Path必须是字符串.收到false
- 如何使用angularjs构建交互式滚动着陆页
- paper.js animation along a path
- 寻找一个免费的交互式美国地图与突出显示的州
- 使用bokeh/flexx-pyscript在Python 3.5中绘制交互式浏览器
- 带有数据输入的PHP/JavaScript web交互式图谱
- 如何制作交互式网站并允许用户编辑网站内容
- 在KML图标中包含交互式HTML5
- html5视频交互式视频播放器
- 创建交互式菜单
- Animating text along an circular path with svg & javascr
- 画布粒子交互式图像
- Raphael Path十字路口不工作
- res.sendFile(path.join(__dirname, '../public', '
- 禁用与只读不适用于非交互式但值保持器输入
- 交互式图表(通过 dc.js)未正确相互更新
- 交互式信息窗口谷歌地图V3
- AngularJS和UI路由器:为什么$state.go()和$location.path()在交互式控制台中不起作用