[Angular] HostListener Method Arguments - Blocking Default Keyboard Behavior
We are going to see how to using method arguments for @HostListener.
First, we can use HostListener without method arguments:
@HostListener('dblclick')
toggle(){
this.collapsed = !this.collapsed;
}
It works fine.
But if we need to get the $event object and do something with it, for example using preventDefault() from the event object. Then we need to use method arguments:
@HostListener('keydown', ['$event', '$event.keyCode'])
onKeyDown($event: KeyboardEvent, keyCode) {if(keyCode !== TAB) {
$event.preventDefault();
}
}
Here we inject '$event' and '$event.keyCode' into the method arguments. So for onKeyDown() method, we are able to inject those as well.
[Angular] HostListener Method Arguments - Blocking Default Keyboard Behavior的更多相关文章
- scala - multiple overloaded alternatives of method bar define default arguments
同名同位置默认参数不能overload def bar(i:Int,s:String="a"){} def bar(i:String,s:String="b") ...
- Default Keyboard Shortcut Schemes
Default Keyboard Shortcut Schemes All ReSharper actions can be invoked with keyboard shortcuts. Most ...
- 【PHP系列】PHP推荐标准之PSR-1,PSR-2
说起码代码,刚上大学那会,老师就教导我们,要严格,规范的,把代码写好.代码如人,工工整整.提起规范化的代码,从一开始用命令行编辑C语言代码就开始控制,强制自己按照相关的标准来,所以,现在写代码,不规范 ...
- H5活动全屏滚动页面在安卓智能电视TV调试
前段时间公司做一个线上活动,在电视上商品促销.产品的要求是每个商品介绍刚好满一屏,按下遥控器向下键可以整屏切换.这种功能如果实在PC端,实现起来非常容易,引用jQuery插件就能实现.但是在安卓智能电 ...
- Interface default method介绍
一.introduce interface default method Introduce default methodWrite the default method at interfaceTh ...
- Fedora 22中的Locale and Keyboard Configuration
Introduction The system locale specifies the language settings of system services and user interface ...
- angular源码分析:angular的整个加载流程
在前面,我们讲了angular的目录结构.JQLite以及依赖注入的实现,在这一期中我们将重点分析angular的整个框架的加载流程. 一.从源代码的编译顺序开始 下面是我们在目录结构哪一期理出的an ...
- Angular源代码学习笔记-原创
时间:2014年12月15日 14:15:10 /** * @license AngularJS v1.3.0-beta.15 * (c) 2010-2014 Google, Inc. http:// ...
- angular核心原理解析1:angular自启动过程
angularJS的源代码整体上来说是一个自执行函数,在angularJS加载完成后,就会自动执行了. angular源代码中: angular = window.angular || (window ...
随机推荐
- 漫漫人生路,学点Jakarta基础-Java8函数式编程
接口默认方法 Java8版本以后新增了接口的默认方法,不仅仅只能包含抽象方法,接口也可以包含若干个实例方法.在接口内定义实例方法(但是注意需要使用default关键字) 在此定义的方法并非抽象方法,而 ...
- js数组sort方法详解
在处理数组的时候,我们有时候需要对数组进行排序,排序的方法有很多种,但是最好最快的就是利用sort方法进行快速的排序. 我们来看一个例子: var arr1 = [6, 3, 4, 1, 2, 5, ...
- POJ 1904 思路题
思路: 思路题 题目诡异地给了一组可行匹配 肯定有用啊-. 就把那组可行的解 女向男连一条有向边 如果男喜欢女 男向女连一条有向边 跑一边Tarjan就行了 (这个时候 环里的都能选 "增广 ...
- Spark Tachyon编译部署(含单机和集群模式安装)
Tachyon编译部署 编译Tachyon 单机部署Tachyon 集群模式部署Tachyon 1.Tachyon编译部署 Tachyon目前的最新发布版为0.7.1,其官方网址为http://tac ...
- coverage python 代码覆盖率工具使用(django 使用)
1. 安装包 pip install coverage 2.启动程序 coverage run -m pytest 3.获取html格式的报告文件 coverage html 4.创建配置文件 .co ...
- [React] Create a queue of Ajax requests with redux-observable and group the results.
With redux-observable, we have the power of RxJS at our disposal - this means tasks that would other ...
- php课程 12-41 多态是什么
php课程 12-41 多态是什么 一.总结 一句话总结:一种请求,多种响应(根据参数类型和数量) 1.function useUsb(Usb $usb){}这句话是什么意思? 判断$usb参数是否实 ...
- Codeforces Round #193 (Div. 2) 部分题解
A:直接判断前三项是否相等 int main() { //FIN; //CHEAT; int n; cin>>n; getchar(); ]; gets(a); int len = str ...
- vue的mode: 'history'模式
const router = new VueRouter({ mode: 'history', routes: [...] }) 不用mode: 'history'的时候,页面url地址后面会加上一个 ...
- centos7.2 64位安装java
1. wget http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk- ...