當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
Angular input控件的click事件表达式如何被转换成JavaScript函数
生活随笔
收集整理的這篇文章主要介紹了
Angular input控件的click事件表达式如何被转换成JavaScript函数
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
源代碼:
<button (click)="toggle($event)">隱藏/顯示</button>這個表達式toggle($event),如何被Angular轉換成的JavaScript函數呢?
通過調試,找到Angular視圖渲染的地方:
renderView和executeTemplate:
下面這個函數就是將表達式轉換成Angular JavaScript listener的地方:
/*** Adds an event listener to the current node.** If an output exists on one of the node's directives, it also subscribes to the output* and saves the subscription for later cleanup.** \@codeGenApi* @param {?} eventName Name of the event* @param {?} listenerFn The function to be called when event emits* @param {?=} useCapture Whether or not to use capture in event listener* @param {?=} eventTargetResolver Function that returns global target information in case this listener* should be attached to a global object like window, document or body** @return {?}*/ function ??listener(eventName, listenerFn, useCapture = false, eventTargetResolver) {/** @type {?} */const lView = getLView();/** @type {?} */const tView = getTView();/** @type {?} */const tNode = getPreviousOrParentTNode();listenerInternal(tView, lView, lView[RENDERER], tNode, eventName, listenerFn, useCapture, eventTargetResolver);return ??listener; }
要獲取更多Jerry的原創文章,請關注公眾號"汪子熙":
總結
以上是生活随笔為你收集整理的Angular input控件的click事件表达式如何被转换成JavaScript函数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 科沃斯发布2022年财报:营收150亿元
- 下一篇: 2023中国清洁电器行业高峰论坛:共话新