加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

AngularJS:是ng-click“好的做法”吗?为什么在AngularJS中没有

发布时间:2020-12-17 09:02:52 所属栏目:安全 来源:网络整理
导读:我刚开始学习AngularJS,并与AngularJS的一些概念斗争。这将是巨大的,如果有人可以解释我一些点… 我知道ng-click在技术上不同于onclick(见here),但两者都放置在标记中。我以为这将是一个“坏的做法”?为什么这是AngularJS的核心概念之一,如果大多数人说
我刚开始学习AngularJS,并与AngularJS的一些概念斗争。这将是巨大的,如果有人可以解释我一些点…

>我知道ng-click在技术上不同于onclick(见here),但两者都放置在标记中。我以为这将是一个“坏的做法”?为什么这是AngularJS的核心概念之一,如果大多数人说这是“坏”?我认为最好从JavaScript中选择DOM元素,而不是在标记中放置逻辑。
>如果ng-click是对AngularJS中的点击事件做出反应的正确方法,我应该如何处理其他DOM事件?我看到有几个其他指令,如ng-mouSEOver,但不是所有的DOM事件都有一个AngularJS等价。我将如何处理AngularJS中的一个“drop”事件(因此在AngularJS方式 – 不是正常的方式)?要明确:我想drag a file into my webapp。

非常感谢你,
Pipo

Why is this one of the core concepts of AngularJS,if most people say this is “bad”?

那么,真正喜欢Unobtrusive JavaScript的人可能会说这是坏的。 Angularians(和那些有flex背景)看到更多的声明性方法的价值。

“Angular is built around the belief that declarative code is better than imperative when it comes to building UIs and wiring software components together… By declaratively describing how the UI should change as your application state changes,you are freed from low level DOM manipulation tasks. — 07001

参见Don’t the data attribute options used in Bootstrap,Angular.js,and Ember.js conflict with Unobtrusive Javascript principles?

what should I do with other DOM events?

编写自己的指令来监听它们(或找到别人已经写的指令)。 Angular让你有能力通过编写自己的指令来扩展浏览器可以做什么。

更新:在下面的评论中,Tim Stewart提到AngularUI的ui-event,它允许你绑定一个回调到Angular本身不支持的任何事件。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读