Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

html事件写法 #89

Open
deepthan opened this issue Sep 10, 2020 · 0 comments
Open

html事件写法 #89

deepthan opened this issue Sep 10, 2020 · 0 comments
Labels

Comments

@deepthan
Copy link
Owner

html事件写法

angular中事件的写法格式是

<p (eventName)="yourEventName()"></p>

1. 点击事件写法及说明

<a  (click)='onClick()'> 点击事件  </a> 
  • click表示我们要处理这个a的点击事件,
  • () 圆括号是说发生此事件时,调用等号后面的表达式或函数。
  • 等号后面的 onClick() 是我们定义在组件中的函数名字。

2. 右键点击自定义菜单

在html元素中绑定右击事件

<div  (contextmenu)="onRightClick($event)">我是一个节点</div>

在js中定义事件处理方法,其中event.preventDefault()可以阻止默认右键菜单的出现。

onRightClick(event) {
    event.preventDefault();
    console.log("右键点击了");
}
@deepthan deepthan added the event label Sep 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant