Cannot read property 'showNotification' of undefined
See original GitHub issueProblem 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:
- Created 7 years ago
- Comments:9 (5 by maintainers)
Top GitHub Comments
I think this issue was opened before i split the library to two
this is a closed issue but anyway, make sure the dependency simple-web-notification is installed and loaded