AngularJS:是NG-按一下[一个很好的做法和QUOT ;?为什么没有NG- {}事件在AngularJS? [英] AngularJS: Is ng-click "a good practice"? Why is there no ng-{event} in AngularJS?

查看:145
本文介绍了AngularJS:是NG-按一下[一个很好的做法和QUOT ;?为什么没有NG- {}事件在AngularJS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始学AngularJS和AngularJS的一些概念奋斗。这将是巨大的,如果有人可以解释我的一些要点...


  1. 据我所知, NG-点击在技术上是不一样的的onclick (见的此处),但两者都放置在标记。我认为这将是一个不好的做法?为什么是AngularJS的核心概念这一块,如果大多数人说这是坏?我认为这将是更好的选择从JavaScript的DOM元素,而不是放置逻辑的标记。


  2. 如果 NG-点击是应对单击AngularJS我应该与其他DOM事件做事件的正确方法?我看到有其他几个指令,比如 NG-鼠标悬停,但不是所有的DOM事件有一个AngularJS等价的。我将如何处理AngularJS一个降事件(因此在AngularJS的方式 - 而不是正常的方式)?需要明确的是:我想拖动文件到我的webapp <​​/A>


非常感谢你,
PIPO


解决方案

  

为什么这是一个AngularJS的核心概念,如果大多数人说这是坏?


唉,人谁真正喜欢非侵入式JavaScript 可能会说这是坏的。 Angularians(和那些与柔性背景)看到更多的声明方式的价值。


  

角围绕信念声明code比势在必行更好,当谈到构建UI和布线软件组件一起......通过声明的方式描述用户界面应该如何为您的应用程序状态的改变而改变建,你是从低层次的DOM操作任务中解脱出来 - 。概述DOC


又见<一个href=\"http://stackoverflow.com/questions/12978507/dont-the-data-attribute-options-used-in-bootstrap-angular-js-and-ember-js-con\">Don't数据属性的引导,Angular.js,并与非侵入式JavaScript原则Ember.js冲突的选项?


  

是我应该做的与其他DOM事件?


编写您自己的指令来听他们(或者找到一个别人已经写的)。角让您可以扩展什么浏览器可以做电源 - 通过编写自己的指令

更新:在下面的意见,蒂姆·斯图尔特提到AngularUI的 UI事件,它可以让你的回调绑定到任何事件本身不被角的支持。

I just started to learn AngularJS and struggle with some concepts of AngularJS. It would be great if somebody could explain me some points...

  1. I understand that ng-click is technically not the same as onclick (see here), but both are placed in the markup. I thought that would be a "bad practice"? Why is this one of the core concepts of AngularJS, if most people say this is "bad"? I thought it would be better to select the DOM element from JavaScript and not to place logic in the markup.

  2. If ng-click is the right way to react to click events in AngularJS what should I do with other DOM events? I see that there are several other directives like ng-mouseover, but not all DOM events have a AngularJS equivalent. How would I handle a 'drop' event in AngularJS (hence in the AngularJS way - not the normal way)? To be clear: I want to drag a file into my webapp.

Thank you very much, Pipo

解决方案

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

Well, people who really like Unobtrusive JavaScript might say it is bad. Angularians (and those with a flex background) see value in the more declarative approach.

"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. -- Overview doc

See also 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?

Write your own directives to listen for them (or find one that someone else has already written). Angular gives you the power to extend what the browser can do -- by writing your own directives.

Update: in the comments below, Tim Stewart mentions AngularUI's ui-event, which lets you bind a callback to any event not natively supported by Angular.

这篇关于AngularJS:是NG-按一下[一个很好的做法和QUOT ;?为什么没有NG- {}事件在AngularJS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆