question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: newToast.scope.init is not a function

See original GitHub issue

I’m using angular-toastr in my project and i’ve got this error, when first toastr appears.

TypeError: newToast.scope.init is not a function
  File http://page.com/js/vendor.js line 73525 col 15 in _notify/</</<
  File http://page.com/js/vendor.js line 22503 col 27 in processQueue
  File http://page.com/js/vendor.js line 22519 col 27 in scheduleProcessQueue/<
  File http://page.coml/js/vendor.js line 14151 col 7 in completeOutstandingRequest
  File http://page.com/js/vendor.js line 14539 col 7 in Browser/self.defer/timeoutId<

Unfortunately, this error appear always on server (for first toastr) and only one on my local machine.

This is my config:

angular.extend(toastrConfig, {
  closeButton: false,
  iconClasses: {
    info: 'toast-message',
    warning: 'toast-cart'
  },
  templates: {
    toast: 'templates/common/services/alersts_service/alertsServ.html'
  }
});

I’m inlcuding angular-toastr.tpls.js script in my html files.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:43 (20 by maintainers)

github_iconTop GitHub Comments

1reaction
danielcmorriscommented, Mar 31, 2017

THE FIX:

I’ve had this problem for ages and just ignored it, but I finally got to it. Someone here even pointed it out and it worked. $templateCache.




    app.config(function (toastrConfig:any) {
        angular.extend(toastrConfig, {
            allowHtml: false,
            closeButton: false,
            closeHtml: '<button>&times;</button>',
            extendedTimeOut: 1000,
            iconClasses: {
                error: 'toast-error',
                info: 'toast-info',
                success: 'toast-success',
                warning: 'toast-warning'
            },
            messageClass: 'toast-message',
            onHidden: null,
            onShown: null,
            onTap: null,
            progressBar: false,
            tapToDismiss: true,
            templates: {
                toast: 'toast.html',
                progressbar: 'progressbar.html'
            },
            timeOut: 5000,
            titleClass: 'toast-title',
            toastClass: 'toast'
        });
    });


    app.run(['$templateCache',function ($templateCache:any) {
        
        $templateCache.put('toast.html', `
            <div class="{{toastClass}} {{toastType}}" ng-click="tapToast()">
                <div ng-switch on="allowHtml">
                    <div ng-switch-default ng-if="title" class="{{titleClass}}" aria-label="{{title}}">{{title}}</div>
                    <div ng-switch-default class="{{messageClass}}" aria-label="{{message}}">{{message}}</div>
                    <div ng-switch-when="true" ng-if="title" class="{{titleClass}}" ng-bind-html="title"></div>
                    <div ng-switch-when="true" class="{{messageClass}}" ng-bind-html="message"></div>
                </div>
                <progress-bar ng-if="progressBar"></progress-bar>
            </div>`);

        $templateCache.put('progressbar.html', `<div class="toast-progress"></div>`);



    }]);

you’ll notice that I changed the config so toast.html and progressbar.html have no paths.
Then I force toast.html and progressbar.html into the cache.

I think the problem was simply that the template just didn’t load fast enough. Was driving me nuts, because I couldn’t get it to happen on my local server, but the production machine had the bug.

Anyway, if you’re having trouble, try just cutting and pasting that code into yours. If it works, boom, you’re done.

1reaction
Foxandxsscommented, Oct 12, 2016

It should be fixed, but apparently not. Would you be able to reproduce this in a plunker or a little project at github? I would like to try.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: showToastrMessage.init is not a function
What are you trying do do? If you want to run showToastrMessage function, try showToastrMessage() instead of showToastrMessage.init() .
Read more >
How to resolve the error 'TypeError: undefined is not a function ...
Therefore you shouldn't use the instance method like this: var ap = new Ansprechpartner();. $scope.nameDuplicates = ap.$searchByName(.
Read more >
AngularJS 1.4.x and Angular Toastr custom properties not ...
$scope.showCustomToast = function() { toastr.error('This toast should be in the ... container).then(function() { newToast.scope.init(); }); } else { var ...
Read more >
Getting Error "Toastr Is Not A Function Error" When Trying To ...
I'm using angulartoastr in my project and i've got this error when first toastr appears.TypeError: newToast.scope.init is not a function. Step 2: Triggering...
Read more >
How to fix "Uncaught TypeError: x is not a function" in JavaScript
JS Casts 01 - How to fix "Uncaught TypeError : x is not a function " in JavaScript.Visit https://javascriptcasts.com/episodes/01 for a summary ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found