Javascript 防止在有父ng单击时触发嵌套ui sref
实际情况与之相反 我想单击一个具有ui sref的嵌套元素,但是应该(有条件地)只触发父元素ng click,从而停止向嵌套子元素的传播 这是我的密码:Javascript 防止在有父ng单击时触发嵌套ui sref,javascript,angularjs,angular-ui-router,Javascript,Angularjs,Angular Ui Router,实际情况与之相反 我想单击一个具有ui sref的嵌套元素,但是应该(有条件地)只触发父元素ng click,从而停止向嵌套子元素的传播 这是我的密码: // Template: <div ng-click="canClick && openAnotherLink($event)"> <a ui-sref="myState"> I wanna click here to trigger the parent ng-click.
// Template:
<div ng-click="canClick && openAnotherLink($event)">
<a ui-sref="myState">
I wanna click here to trigger the parent ng-click.
Overriding the default ui-sref behavior
</a>
</div>
// Controller:
$scope.canClick = true;
$scope.openAnotherLink = ($event) => {
$event.stopPropagation(); // <-- this does not works
// $event.preventDefault() // <-- I tried even this, not working
window.open('http://google.com', '_blank');
return;
}
//模板:
我想点击这里触发父母的点击。
覆盖默认ui sref行为
//控制器:
$scope.canClick=true;
$scope.openAnotherLink=($event)=>{
$event.stopPropagation();//可以使用$state代替ui sref。进入控制器内部:
// Template:
<div ng-click="canClick && openAnotherLink()">
<a ng-click="goToState($event)">
I wanna click here to trigger the parent ng-click.
Overriding the default ui-sref behavior
</a>
</div>
// Controller: I assume you injected the "$state" provider
$scope.canClick = true;
$scope.openAnotherLink = () => {
window.open('http://google.com', '_blank');
}
$scope.goToState = function goToState(e) {
if (!$scope.canClick) {
e.stopPropagation();
$state.go("myState");
}
};
//模板:
我想点击这里触发父母的点击。
覆盖默认ui sref行为
//控制器:我假设您注入了“$state”提供程序
$scope.canClick=true;
$scope.openAnotherLink=()=>{
打开窗户http://google.com","空白",;
}
$scope.goToState=函数goToState(e){
如果(!$scope.canClick){
e、 停止传播();
$state.go(“myState”);
}
};