我想在浏览器遵循ui-router动态创建的链接之前验证某些条件.
我正在调查,$rootscope.$on('$stateChangeStart', ..)但我无法访问controller.$scope那里.我还需要在应用程序的几个地方使用它,并且会很麻烦.
请记住ui-sref链接到ui-sref-active(一起工作),所以我不能删除,ui-sref并且说,$state.$go('some-state')在一个名为with的函数内使用ng-click.
应该在a $scope function和a之内评估条件on-click event(在转换之前能够取消它)
我需要这样的东西:
<li ui-sref-active="active">
<a ui-sref="somestate" ui-sref-if="model.validate()">Go Somestate</a>
</li>
Run Code Online (Sandbox Code Playgroud)
我试过了:
<li ui-sref-active="active">
<a ui-sref="somestate" ng-click="$event.preventDefault()">Go Somestate</a>
</li>
<li ui-sref-active="active">
<a ui-sref="somestate" ng-click="$event.stopImmediatePropagation()">Go Somestate</a>
</li>
Run Code Online (Sandbox Code Playgroud)
和
<li ui-sref-active="active">
<a ui-sref="somestate">
<span ng-click="$event.stopPropagation();">Go Somestate</span>
</a>
</li>
Run Code Online (Sandbox Code Playgroud)
甚至
<li ui-sref-active="active">
<a ui-sref="somestate" onclick="return false;">Go Somestate</a>
</li>
Run Code Online (Sandbox Code Playgroud)
但是不起作用.
例如:
$stateProvider
.state('external', {
url: 'http://www.google.com',
})
Run Code Online (Sandbox Code Playgroud)
url假设这是一个内部状态.我希望它像href或者那种效果.
我有一个将从ui路由构建的导航结构,我需要一个链接转到外部链接.不一定只是谷歌,这只是一个例子.
不是在链接中查找,也不是在$ state.href(' http://www.google.com ')中查找.在路由配置中以声明方式需要它.
routing angularjs single-page-application angularjs-routing angular-ui-router