on my site, i currently have a modal that is opened. when the user clicks on the button to close the modal, it calls:
$scope.hideModal = function(modalId) {
angular.element(modalId).hide();
DatabaseService.updateDB();
};
DatabaseService is a seperate .js class that contains methods to make read/changes to the database
var _updateDashboardInterstitialPromoDbService = function(){
//code to update the database
}
When I run my site, the modal closes successfully, but i see an error in my console:
TypeError: undefined is not a function at h.$scope.hideModal
How do I resolve this typeerror to successfully call the function to update my database?
Here's my ModalCtrl.js
'use strict';
var DashboardCtrl =
[
'$scope',
'DashboardInterstitialPromoService',
function ($scope, DashboardInterstitialPromoService) {
$scope.hideModal = function(modalId) {
angular.element(modalId).hide();
DatabaseService.updateDB();
};
];
Here's my DatabaseService.js:
'use strict';
var databaseService = angular.module('database.service', ['ngResource']);
databaseService.factory('DatabaseService',
[
function() {
var _updateDB = function(){
//stuff to update db
};
return {updateDB: _updateDB};
}]);
DatabaseServiceand how are you getting it in to your controller?DatabaseServiceand itsupdateDBmethod. Show how you're injecting it into your controller