1

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};
}]);
4
  • What is DatabaseService and how are you getting it in to your controller? Commented Dec 9, 2014 at 1:08
  • DatabaseService is a completely seperate .js file. In my controller, MainCtrl.js, I injected DatabaseService.js. So it looks something like: var MainCtrl = ['DatabaseService', function (DatabaseService) { etc. Commented Dec 9, 2014 at 1:11
  • So it's a registered factory / service? You're really going to have to add some more code to your question. Show where you define DatabaseService and its updateDB method. Show how you're injecting it into your controller Commented Dec 9, 2014 at 1:15
  • Also see that you have the code file hooked up to the parent html page. Usually done through a <script> tag. Commented Dec 9, 2014 at 1:31

1 Answer 1

2

You have not included DatabaseService in your controller. It should look something like this-

'use strict';
var DashboardCtrl =
[
    '$scope',
    'DashboardInterstitialPromoService',
     'DatabaseService',
    function ($scope, DashboardInterstitialPromoService,DatabaseService) {
        $scope.hideModal = function(modalId) {
        angular.element(modalId).hide();
        DatabaseService.updateDB();
    };
];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.