1

这个角度服务适用于未编译的 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;
 }

任何一种形式都未编译。

谁能建议如何以一种对闭包编译友好的方式来做到这一点?

4

0 回答 0