alexcrack / angular-ui-notification

Angular.js service providing simple notifications using Bootstrap 3 styles with css transitions for animating
MIT License
536 stars 169 forks source link

Unable to use custom tamplates #115

Closed estankovic closed 7 years ago

estankovic commented 7 years ago

Hi, I am having an issue with custom templates. If custom template is inlined in anz of views it works ok. Problem is when I try to load template from url. Url is working, in console I get file with 200 header and propper content, but this error appears:

Error: Template (build/js/views/notifications/import/ImportSuccessful.html) could not be loaded. TypeError: Cannot read property 'ownerDocument' of undefined
    at http://minsets.dev/catalogue/build/js/vendor.js:16371:27
    at http://minsets.dev/catalogue/build/js/vendor.js:9349:460
    at m.$eval (http://minsets.dev/catalogue/build/js/vendor.js:9363:313)
    at m.$digest (http://minsets.dev/catalogue/build/js/vendor.js:9360:421)
    at m.$apply (http://minsets.dev/catalogue/build/js/vendor.js:9364:78)
    at l (http://minsets.dev/catalogue/build/js/vendor.js:9317:89)
    at XMLHttpRequest.t.onload (http://minsets.dev/catalogue/build/js/vendor.js:9322:489) Possibly unhandled rejection: {}

code used to load notofication:

Notification.primary({message: "Just message", templateUrl: 'build/js/views/notifications/import/ImportSuccessful.html'});

any advice will be appreciated

Marcosdg3 commented 7 years ago

I duplicated this same issue using Angular 1.6.1 and jQuery 3.1.1. I was also able to duplicate without the newer version of jQuery and just using Angular's jqlite. I was able to make custom templates only work when defined they are defined in a script tag, which is why the tests may have passed (haven't been able to get them working locally yet). If they require an http request then this error will be displayed because the template isn't being extracted from the response. I submitted a fix https://github.com/alexcrack/angular-ui-notification/pull/117

Before: https://plnkr.co/edit/aIKViGiCZUul4wVqd5Vn

                  $http.get(args.template,{cache: true})
                  .then(processNotificationTemplate)
                  .catch(function(data){
                    throw new Error('Template ('+args.template+') could not be loaded. ' + data);
                  }); 

After: https://plnkr.co/edit/3iPnF3X4IvE5lfqtuXlO

                  $http.get(args.template,{cache: true})
                  .then(function(response){
                    processNotificationTemplate(response.data);
                  })
                  .catch(function(data){
                    throw new Error('Template ('+args.template+') could not be loaded. ' + data);
                  });   

I would also like to update the tests with your help @alexcrack :)

bmeiri commented 7 years ago

Any update on this? We can't use the script tag in our solution

alexcrack commented 7 years ago

fixed in 043795ea772740e5a853c3ff54657c1bb2fb8a28

pushys commented 7 years ago

This error doesn't seem to be fixed while installing the library through npm, in the source code I still see the previous invalid lines:

$http.get(args.template,{cache: true})
    .then(processNotificationTemplate)
    .catch(function(data){
        throw new Error('Template ('+args.template+') could not be loaded. ' + data);
    });   

The npm page says that it has an actual version 0.3.5, but downloads a wrong packet.

alexcrack commented 7 years ago

Yes. Package on npm will be updated soon.

germanoroettgers commented 7 years ago

Please update on Bower too, still the same problem

alexcrack commented 7 years ago

Updated