Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Namespacing events in Javascript/AngularJS?

I'm wondering if is there a naming convention to namespacing events with AngularJS?

jQuery defines its convention as event.namespace (with namespace at the end, and dot separator)

I've seen some articles (example) where events are named like this: namespace::event (with namespace at the start; and double-colon separator)

Is there a common practice on this subject?

Thanks for your thoughts about it.

like image 666
arnaud.breton Avatar asked Apr 27 '13 06:04

arnaud.breton


People also ask

What is Event binding in AngularJS?

In Angular 8, event binding is used to handle the events raised by the user actions like button click, mouse movement, keystrokes, etc. When the DOM event happens at an element(e.g. click, keydown, keyup), it calls the specified method in the particular component.

Can we use document getElementById in AngularJS?

You can use document. getElementById() in Angularjs, but manipulating HTML in a controller is not a good practice.

What is event handler in angular?

In an event binding, Angular configures an event handler for the target event. You can use event binding with your own custom events. When the component or directive raises the event, the handler executes the template statement. The template statement performs an action in response to the event.

What is angular element this scope ()?

The angular. element() Function in AngularJS is used to initialize DOM element or HTML string as an jQuery element. If jQuery is available angular. element can be either used as an alias for jQuery function or it can be used as a function to wrap the element or string in Angular's jqlite.


1 Answers

I haven't heard of anything specific regarding angular, but you should consider that namespacing is a generally good practice for many situations. If you're writing a simple app that won't incorporate other scripts, there isn't much need to namespace. Just consider what could happen in the future of your script's environment (whether event's names could end up clashing) and base your decision on that.

like image 151
m59 Avatar answered Sep 30 '22 17:09

m59