在我的网站上,我目前有一个打开的模态。当用户点击按钮关闭模态时,它会调用:
$scope.hideModal = function(modalId) {
angular.element(modalId).hide();
DatabaseService.updateDB();
};
DatabaseService是一个单独的.js类,包含对数据库进行读取/更改的方法
var _updateDashboardInterstitialPromoDbService = function(){
//code to update the database
}
当我运行我的网站时,模态成功关闭,但我在控制台中看到错误:
TypeError:undefined不是函数 at h。$ scope.hideModal
如何解决此类型错误以成功调用函数来更新我的数据库?
这是我的ModalCtrl.js
'use strict';
var DashboardCtrl =
[
'$scope',
'DashboardInterstitialPromoService',
function ($scope, DashboardInterstitialPromoService) {
$scope.hideModal = function(modalId) {
angular.element(modalId).hide();
DatabaseService.updateDB();
};
];
这是我的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};
}]);
答案 0 :(得分:2)
您尚未在控制器中加入DatabaseService
。看起来应该是这样的 -
'use strict';
var DashboardCtrl =
[
'$scope',
'DashboardInterstitialPromoService',
'DatabaseService',
function ($scope, DashboardInterstitialPromoService,DatabaseService) {
$scope.hideModal = function(modalId) {
angular.element(modalId).hide();
DatabaseService.updateDB();
};
];