Hey Harshit,
yes, it is possible. For advices applied at any pointcut you have access to
the arguments of the woven method and for some pointcuts (like after) you
have access to the return value as well.
Here is a basic demo:
// Advice
DemoApp.factory('Logger', function () {
return function (data) {
var result = ['Method: ' + data.method,
'Pointcut: ' + data.when, 'Arguments: ' + data.args.join(', '),
(data.when === 'After') ? 'Return value: ' + data.result : '']
console.log(result.join('\n'));
};
});
// Service, which will be woven with the advice above
DemoApp.factory('DummyService', function () {
return {
foo: function () {
console.log('I\'m in foo!');
},
bar: function (arg1, arg2) {
console.log('I\'m in bar! Arguments:', arg1, arg2);
return 2;
}
};
});
// "Annotation" of the service
DemoApp.config(function ($provide, executeProvider) {
executeProvider.annotate($provide, {
DummyService: [{
jointPoint: 'after',
advice: 'Logger'
}]
});
});
// Invocation of the service's method
DemoApp.controller('ArticlesListCtrl', function (DummyService) {
DummyService.bar(42, 1.618);
});
// Result:
/**************************
Method: bar
Pointcut: After
Arguments: 42, 1.618
Return value: 2
***************************/
Best,
Minko <https://github.com/mgechev>
On Thursday, 18 September 2014 20:52:39 UTC+3, Harshit Rohatgi wrote:
>
> HI Minko ,
> The examples you gave have an advice which is args free. Is there a way ,
> we can pass the arguments from the pointcut to advice. Essentially I want
> to log the metrics at the point cut. So i would like to get some state
> variables from there and send it to my code.
>
> On Wednesday, 7 August 2013 13:11:55 UTC, Minko Gechev wrote:
>>
>> Hello guys,
>>
>> I've always made some parallels between SpringSource and AngularJS - at
>> least the DI and abstraction they provide.
>> The next key aspect from SpringSource which I think might be useful while
>> developing AngularJS applications is the AOP (Aspect-Oriented Programming).
>>
>> I built a simple AOP framework for AngularJS which can be found at
>> https://github.com/mgechev/angular-aop
>>
>> I tried to make it with the simplest possible interface, I hope it'll be
>> useful for you. It's totally open for contributions if you have ideas for
>> it!
>>
>> Best regards,
>> Minko.
>>
>
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.