@click.stop在angular中怎么写
时间: 2024-05-16 12:18:58 浏览: 156
“暂停”按钮代码
在Angular中,@click.stop可以通过以下两种方式来实现:
方式一:
在模板中的按钮元素上使用`(click)="$event.stopPropagation(); doSomething()"`来阻止事件冒泡。例如:
```html
<div>
<button (click)="$event.stopPropagation(); doSomething()">Click me</button>
</div>
```
方式二:
在组件文件中使用`$event.stopPropagation()`来阻止事件冒泡。例如:
```typescript
@Component({
selector: 'exe-app',
template: `
<div>
<button (click)="doSomething($event)">Click me</button>
</div>
`
})
export class AboutComponent {
doSomething($event: Event) {
$event.stopPropagation();
// 这里是你的逻辑
}
}
```
以上两种方式都可以实现在Angular中使用@click.stop来阻止事件冒泡。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* *3* [Angular 4_ 事件冒泡](https://blog.csdn.net/qq_36279445/article/details/78905315)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 100%"]
[ .reference_list ]
阅读全文