![Create React App Officially Deprecated Amid React 19 Compatibility Issues](https://cdn.sanity.io/images/cgdhsj6q/production/04fa08cf844d798abc0e1a6391c129363cc7e2ab-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
<div ng-on="{ 'event-name': handlerFn }"></div>
Directive for Angular 1.x to easily bind custom (or not) events
Angular provides some useful directives for attaching event handlers easily:
ng-click="$ctrl.clickHandler()"
;ng-change="$ctrl.changeHandler($event)"
;ng-mouseenter="$ctrl.mouseenterHandler($event)"
etc.But for custom events it's a tad more work, you need to set event listener on element yourself.
You might do something like this:
angular
.module('myModule')
.directive('myDirective', function() {
return {
link: function(scope, element) {
element.on('custom-event', function(event) {
console.log('handling custom event', event.type);
});
}
};
});
or do something similar in controller and injected $element
.
this is fine for few bindings but gets tedious for setting up many events on many different elements.
Enter the angularisher way of doing this with ng-on
!
<div ng-on="{ 'event-name': handlerFn }"></div>
event-name
- name of event you want to listen to. Can be any event that element fires (also regular click
, mouseenter
etc.);handlerFn
- a reference to function which is in components scope (i.e. controller of directive/component must expose this function). The function is called with event
attribute.npm i ng-on --save
angular.module('yourModule', ['argshook.ngOn'])
notice the use of component
no need for link
anymore:
angular
.module('myModule')
.component('myComponent', {
template: '<div ng-on="{ \'custom-event\': $ctrl.customEventHandler }">{{$ctrl.eventValue}}</div>',
controller: function() {
this.customEventHandler = function(event) {
this.eventValue = event.value;
};
}
});
you can also define multiple event handlers (this time ng-on
value is in controller):
angular
.module('myModule')
.component('myComponent', {
template: '<div ng-on="$ctrl.eventsObj">{{$ctrl.eventValue}}</div>',
controller: function() {
this.eventsObj = {
'custom-event': customEventHandler
'another-custom-event': anotherCustomEventHandler,
click: clickHandler // you can handle regular DOM events too
};
function customEventHandler(event) {
this.eventValue = event.value;
};
this.anotherCustomEventHandler = function(event) {
console.log(event.type); // <= another-custom-event
};
this.clickHandler = function() {
console.log(event.type); // <= click
};
}
});
FAQs
Directive for Angular 1.x to easily bind custom (or not) events
The npm package ng-on receives a total of 0 weekly downloads. As such, ng-on popularity was classified as not popular.
We found that ng-on demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.