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.

Cannot read property 'showNotification' of undefined

See original GitHub issue

Problem Description

Cool module! thanks!

I am trying to use this in my project but it appears that this moduleis not getting injected properly?

its built with webpack, ES6 and angular 1.5.8.

Is the angular-web-notification.js file set up to be exported and used as a module?

Code Example


  function vmListCtrl($location, $q, $rootScope, config, dataservice, logger, vmCache, webNotification) {

    /*jshint validthis: true */
    var ctrl = this;

    ctrl.vms = [];

    ctrl.searchFlag = false;
    ctrl.search = {
      status: '!DELETED'
    };

    ctrl.$onInit = function () {
      var promises = [getVMs()];
      return $q.all(promises).then(function () {
        logger.info('Activated vm-list View', config.uiMsgTitle);

        $rootScope.$on('VMsChanged', function () {
          resetAll();
          getVMs();
        });
      });
    };

    function resetAll() {
      ctrl.vms = [];
    }

    function getVMs() {
      return dataservice.getVMs()
        .then(function (data) {
          ctrl.vms = vmCache.get('vms');
          if (ctrl.vms && ctrl.vms.length > 0) {
            ctrl.vms.sort(function (a, b) {
              return a.vm_name > b.vm_name;
            });
          }
        });
    }

    ctrl.searchChanged = function () {
      if (ctrl.searchFlag) {
        ctrl.search.status = '';
      } else {
        ctrl.search.status = '!DELETED';
      }
    };

    ctrl.loadDetails = function (vmName) {
      $location.path('/vm-detail/' + vmName);
    };

    ctrl.vmCreate = function () {
      $location.path('/vm-create');
    };

    ctrl.showAlert = function () {
      webNotification.showNotification(scope.notificationTitle, {
        body: 'scope.notificationText',
        onClick: function onNotificationClicked() {
          console.log('Notification clicked.');
        },
        autoClose: 4000 //auto close the notification after 4 seconds (you can manually close it via hide function)
      }, function onShow(error, hide) {
        if (error) {
          window.alert('Unable to show notification: ' + error.message);
        } else {
          console.log('Notification Shown.');

          setTimeout(function hideNotification() {
            console.log('Hiding notification....');
            hide(); //manually close the notification (you can skip this if you use the autoClose option)
          }, 5000);
        }
      });
    }


  }
export default vmListCtrl;

Error Stack/Info (if any)

angular.js?7f65:13920 TypeError: [NG-Modular Error] Cannot read property ‘showNotification’ of undefined at vmListCtrl.ctrl.showAlert (eval at 144 (http://localhost:8080/bundle.js:4:17283), <anonymous>:63:20) at fn (eval at compile (eval at <anonymous> (http://localhost:8080/vendor.bundle.js:32:27247)), <anonymous>:4:265) at expensiveCheckFn (eval at <anonymous> (http://localhost:8080/vendor.bundle.js:32:27247), <anonymous>:15906:18) at callback (eval at <anonymous> (http://localhost:8080/vendor.bundle.js:32:27247), <anonymous>:25885:17) at Scope.$eval (eval at <anonymous> (http://localhost:8080/vendor.bundle.js:32:27247), <anonymous>:17682:28) at Scope.$apply (eval at <anonymous> (http://localhost:8080/vendor.bundle.js:32:27247), <anonymous>:17782:25) at HTMLButtonElement.eval (eval at <anonymous> (http://localhost:8080/vendor.bundle.js:32:27247), <anonymous>:25890:23) at defaultHandlerWrapper (eval at <anonymous> (http://localhost:8080/vendor.bundle.js:32:27247), <anonymous>:3497:11) at HTMLButtonElement.eventHandler (eval at <anonymous> (http://localhost:8080/vendor.bundle.js:32:27247),

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
sagieguraricommented, Jul 11, 2017

I think this issue was opened before i split the library to two

0reactions
sagieguraricommented, Aug 22, 2018

this is a closed issue but anyway, make sure the dependency simple-web-notification is installed and loaded

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot read property 'showNotification' of undefined
i'm using create-react-app with PWA and just can't work notifications api :( this ...
Read more >
Cannot read property 'showNotification' of undefined-Reactjs
Coding example for the question Cannot read property 'showNotification' of undefined-Reactjs.
Read more >
ServiceWorkerRegistration.showNotification() - Web APIs | MDN
The showNotification() method of the ServiceWorkerRegistration interface creates a notification on an active service worker.
Read more >
Notification plugin Cannot read property 'getClientRect' of null
AS you can see my code. 2. You can make another test with disabled toolbar. var notification2 = editor.showNotification( 'Error occurred', 'warning' );...
Read more >
ServiceWorkerRegistration.showNotification - Web APIs
An object that allows configuring the notification. It can have the following properties: actions : An array of actions to display in the ......
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