In fact, for the sake of experimenting, try to inject $rootScope to the 
factory :)

On Thursday, February 13, 2014 9:56:34 PM UTC+1, Jesus Rodriguez wrote:
>
> Hey!
>
> I am afraid that the problem is not about the directive requiring the 
> factory that also creates that directive. That is something we do at 
> ui-bootstrap (check modal.js for example). It is a common pattern to 
> generate directives from a service and that directive using the service to 
> close itself.
>
> The problem is the decorated $exceptionHandler which is really picky with 
> what you inject. Creating an exceptionHandler instead of decorating the 
> existing one and then injecting toastr by hand solves the problem.
>
> Anyway I really appreciate your answer :)
>
> On Thursday, February 13, 2014 9:03:22 PM UTC+1, Martin Alix wrote:
>>
>> That's very hard to solve...
>>
>> Maybe an approach that starts like this:
>>
>>     angular.module('toastr', [])
>>       .config(function($provide) {
>>         $provide.decorator("$exceptionHandler", function($delegate, 
>> toastr) {
>>             return function(exception, cause) {
>>                 toastr.error(exception.message, 'ERROR!');
>>             };
>>         });
>>       })
>>       .directive('toasts', function($compile, toastr) {
>>           return {link:function(scope, element, attrs) {
>>             scope.$watch(toastr.lastToast, function(a,b,s) {
>>               if(a === null) return;
>>               element.append($compile('<pre>' + a + '</pre>')(scope)) 
>> //replace this...
>>             })
>>           }};
>>         })
>>       .factory('toastr', function() {
>>         var toastrs = [];
>>         var index = -1;
>>         return {
>>           lastToast: function() {
>>             if(index === -1) return null;
>>             return toastrs[index].message;
>>           },
>>           error: function(message, title) {
>>               var newToastr = {
>>                 index: index++,
>>                 message: message,
>>                 title: title
>>               };
>>     
>>               toastrs.push(newToastr);
>>           }
>>         };
>>       })
>>       
>>
>> http://plnkr.co/edit/KK1dT3xKDkdqjvTmiaeq?p=preview
>>
>>
>> On Wednesday, February 12, 2014 6:57:06 PM UTC-5, Jesus Rodriguez wrote:
>>>
>>> I am fighting a fight I cannot understand properly so I come here to get 
>>> some knowledge.
>>>
>>> I am porting a jQuery directive to angular. It is to popup alerts. I 
>>> decided to go to the ui-bootstrap $modal route, AKA a directive and a 
>>> factory that will create new directives to append them to the body. So far 
>>> so good, it works perfect for me.
>>>
>>> Even when it is really WIP I decided to swap the jQuery version for my 
>>> version and I got a:
>>>
>>> Uncaught Error: [$injector:cdep] Circular dependency found: $interpolate 
>>> <- $compile <- toastr <- $exceptionHandler <- $rootScope <- $route
>>>
>>> For what I understand, $exceptionHandler is really picky about what you 
>>> inject and normally it suggest you to manual inject with $injector.
>>>
>>> My provider is something like:
>>>
>>> $get: ['$compile', '$document', '$rootScope', function($compile, $document, 
>>> $rootScope) {
>>>
>>>
>>> Both $compile and $rootScope are the problematic here.
>>>
>>>
>>> My question are:
>>>
>>>
>>> Why is $exceptionHandler so picky? I tried to reproduce my problem creating 
>>> a controller using $rootScope and injecting also my provider and it works 
>>> good. It only seems to fail with $exceptionHandler.
>>>
>>>
>>> Should I change my $get? Since it compiles new alerts, I need $compile and 
>>> also $rootScope (to give them a scope)
>>>
>>>
>>> I tried manually getting my library on the exceptionHandler and nothing, it 
>>> still fail and since it is a alert messages, it is normally used as logger 
>>> and logging and $exceptionHandler are friends.
>>>
>>>
>>> Ideas? Thoughts?
>>>
>>>

-- 
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/groups/opt_out.

Reply via email to