Comparing version 0.0.3 to 0.0.4
{ | ||
"name": "ng-on", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "Directive for Angular 1.x to easily bind custom (or not) events", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -33,3 +33,3 @@ # ng-on | ||
this is fine for few small amount of bindings but gets tedious for setting up many events on many different elements. | ||
this is fine for few bindings but gets tedious for setting up many events on many different elements. | ||
@@ -79,8 +79,8 @@ Enter the angularisher way of doing this with `ng-on`! | ||
this.eventsObj = { | ||
'custom-event': this.customEventHandler | ||
'another-custom-event': this.anotherCustomEventHandler, | ||
click: this.clickHandler // you can handle regular DOM events too | ||
'custom-event': customEventHandler | ||
'another-custom-event': anotherCustomEventHandler, | ||
click: clickHandler // you can handle regular DOM events too | ||
}; | ||
this.customEventHandler = function(event) { | ||
function customEventHandler(event) { | ||
this.eventValue = event.value; | ||
@@ -87,0 +87,0 @@ }; |
@@ -22,3 +22,3 @@ ;(function() { | ||
try { | ||
eventsAndCallbacks[eventName](event); | ||
eventsAndCallbacks[eventName].call(scope.$ctrl || scope, event); | ||
} catch(e) { | ||
@@ -25,0 +25,0 @@ throwError(e, eventName); |
@@ -45,2 +45,26 @@ /* global jasmine, describe, it, beforeEach, expect, module, inject, createCompiler */ | ||
}); | ||
it('should call defined event handler with scope.$ctrl as context', function() { | ||
var contextSpy = jasmine.createSpy('contextSpy'); | ||
var parentScope = { | ||
events: { | ||
'but-whole': function(e) { | ||
this.spy(e); | ||
} | ||
}, | ||
spy: contextSpy | ||
} | ||
compile(parentScope, elementAttrsMock, function (scope, element) { | ||
scope = $rootScope.$new(); | ||
element.triggerHandler('but-whole'); | ||
scope.$digest(); | ||
expect(contextSpy).toHaveBeenCalledWith(jasmine.objectContaining({ | ||
type: 'but-whole' | ||
})); | ||
}); | ||
}); | ||
}); | ||
@@ -47,0 +71,0 @@ |
9035
156