driftyco/ng-cordova — pull request #511 by rbecheras (2014-12-17 08:34:26+00:00)
Title: Fix the $cordovaLocalNotification events handling that wasn't work at al...

...l;

This PR fix the issue https://github.com/driftyco/ng-cordova/issues/310.

The folowwing methods are wrapper that must handle the events for the local notifcations :

````javascript
$cordovaLocalNotification.onadd()

$cordovaLocalNotification.ontrigger()

$cordovaLocalNotification.onclick()

$cordovaLocalNotification.oncancel()
```

The previous code just returned the reference to the event property of the plugin :

````javascript
onclick: function () {
return $window.plugin.notification.local.onclick;
},
````
Causing no way to use the method to assign a callback function.

So I refactored the four methods to get a function `fn` in argument and assign it to the plugin event property.

Plus, I rewriten the design of the module defining on top an object `cordovaLocalNotification`, attaching method's service to it and returning it at the end.

Thus, each "event handler" can assign its callback then returning the factory instance and so we can use and chain these methods like this :

````javascript
$cordovaLocalNotification
.onadd(_onAdd)
.ontrigger(_onTrigger)
.onclick(_onClick)
.oncancel(_onCancel);

function _onAdd(id, state, json){
// ...
}
function _onTrigger(id, state, json){
// ...
}
function _onClick(id, state, json){
// ...
}
function _onCancel(id, state, json){
// ...
}
````