SAP UI5和Angular的事件处理机制比较

简介: Recently I am studying Angular in my spare time. And I would like to write down here what I have learned about Angular, comparing its design with UI5. In this blog I will only focus on event handling topic.

Recently I am studying Angular in my spare time. And I would like to write down here what I have learned about Angular, comparing its design with UI5. In this blog I will only focus on event handling topic.


I have already explained how I do self study on UI5 event handling stuff in this blog , and Andreas Kunz has given very thorough comments on the design idea behind the native event and semantic event, you should NOT miss those comment


UI5 event handling

Let’s quickly review what UI5 developers should do if they need to listen to an event. Still use button as example:

Just call function attachPress and pass in our event handling function as argument:

image.png

The button instance itself does not own the function attachPress:


image.png


Instead, it is provided by the node in the button instance’s prototype chain, EventProvider.


image.png


When attachPress is called:


image.png


When we click button in UI:


image.png


image.png

This is very clear. Now let’s move to Angular.


Angular event handling

You can find a sample Angular application. It is written based on Angular 1.2.18.


image.png


image.png

When I first study this application, the attribute “ng-click=”sortField = ‘name’”” seems to me a complete magic: how could a fragment of code in html node attribute executed?


I am sure it is “ng-click” which achieves Angular’s specific way of event handling, so I tried to figure it out by debugging.


Angular framework has its own initialization and bootstrap phase, just the same idea as UI5. During its bootstrap, Angular will traverse the html DOM tree ( line 964, compile function ) and parse the html element node recursively. If an attribute with Angular namespace “ng” is detected within an element node, the detected attribute is called “directive” in Angular and some special logic will be applied on that node, in function “applyDirectivesToNode”.


image.png


Here below is how event registration is done by Angular for us:


image.png


Let’s confirm our assumption. I click hyperlink in UI: the native event “click” is passed to the wrapper function fn in line 15330.


image.png


The wrapper function contains the logic to execute “sortField = ‘name’” specified in html source code.

Its core is implemented via the assign function:


image.png


Finally, scope obj ( you can consider scope as “Model” in UI5 at this moment ) has attribute sortField which has been assigned with a new value “name”, this is how “sortField = ‘name’” is executed.


image.png


image.png

Hope this blog can help you gain a very basic understanding about Angular event handling


相关文章
|
3月前
|
Web App开发 UED 开发者
谈谈企业级 Angular 应用的二次开发 - 基于 Angular Component 替换的 Extensibility 支持案例介绍
谈谈企业级 Angular 应用的二次开发 - 基于 Angular Component 替换的 Extensibility 支持案例介绍
40 1
|
5月前
|
JavaScript 前端开发 API
关于 Angular Universal 应用渲染两次的问题
关于 Angular Universal 应用渲染两次的问题
34 0
|
6月前
|
JavaScript 前端开发 测试技术
angular框架怎么从0到1进行开发
angular框架怎么从0到1进行开发
37 0
|
6月前
|
监控 JavaScript 前端开发
Angular 应用程序的 Hydration 概念详解
Angular 应用程序的 Hydration 概念详解
35 0
|
缓存 前端开发 JavaScript
Angular 结合 NG-ZORRO 快速开发
连更的这几天的文章,我们已经了解了不少 angular 的知识点了,这次我们来个小成品。 angualr 结合 ng-zorro 快速且规范的开发一个后台系统。
Angular 结合 NG-ZORRO 快速开发
|
前端开发 JavaScript
SAP UI5和Angular的事件处理机制比较
SAP UI5和Angular的事件处理机制比较
110 0
SAP UI5和Angular的事件处理机制比较
|
前端开发
SAP UI5和Angularjs事件处理机制的实现比较
SAP UI5和Angularjs事件处理机制的实现比较
103 0
SAP UI5和Angularjs事件处理机制的实现比较
Angular开发模式下的setNgReflectProperties函数
Angular开发模式下的setNgReflectProperties函数
78 0
Angular开发模式下的setNgReflectProperties函数
|
JavaScript 前端开发
Angular数据绑定的学习笔记
https://angular.io/guide/property-binding
Angular数据绑定的学习笔记