此角度服务适用于未编译的javascript。但谷歌关闭编译后,它无法找到服务。难以调试已编译的代码。
你能看出可能出现的问题吗? 在文件1中:
'use strict';
goog.provide('simpleDialogService');
angular.module(‘myApp').service('simpleDialogService', ['$modal',
function ($modal) {
var dialogDefaults = {};
dialogDefaults ['templateUrl'] = "partials/dialog.html";
var dialogOptions = {};
dialogOptions ['cancelButtonVisibility'] = "hidden";
var dialogResults = {};
// other functions, including showDialog()
this[‘showModalDialog’] = function (customDialogDefaults, customDialogOptions) {
if (!customDialogDefaults) customDialogDefaults = {};
customDialogDefaults['backdropClick'] = false;
return this.showDialog(customDialogDefaults, customDialogOptions);
};
}]);
在文件2中:
goog.require('extern.jquery');
goog.require('simpleDialogService');
在file2中调用如下:
function anotherFunction(){
var promise;
var injector = angular.injector(['ng', ‘myApp']);
injector.invoke(['simpleDialogService', function(simpleDialogService){
promise = simpleDialogService['showModalDialog']({}, dialogOptions);
}]);
return promise;
}
或像这样打电话
function anotherFunction2(){
var promise;
var injector = angular.injector(['ng', ‘myApp']);
var myService = theInjector.get('simpleDialogService');
promise = myService['showModalDialog']({}, dialogOptions);
return promise;
}
任何一种形式都是未编译的。
任何人都可以建议如何以闭包编译方式执行此操作吗?