未知提供者:eProvider <-e

时间:2020-10-05 21:45:31

标签: angularjs

我正在更新旧版Angular JS 1.7应用程序并添加一个AngularJS Material Popup modal。该应用程序使用Webpack并在部署到生产环境时进行压缩(请参见以下内容:drop_console = true)。

Webpack:

new TerserPlugin({
    terserOptions: {
        compress: {
            drop_console: (isProduction) ? true : false, // true
        },
    },
}),

我知道Angular要求注入的依赖项用引号引起来,.controller('myCtrl', ['$scope', function($scope) {,因为缩小会更改依赖项的名称,这可能会导致我得到以下错误:

[$injector:unpr] Unknown provider: eProvider <- e ...

但是此模式的工作方式是通过绑定控制器函数,如下所示:

工厂服务:

angular.module('MODULE').factory('myService', ['$mdDialog', 
 function ($mdDialog) {
  return {

   ...

      $mdDialog.show({
        controller: DialogController, // bound to dialog controller below
        ...
      });

      function DialogController($scope, $mdDialog) { // dependencies injected here
        ...

当它们位于模块function DialogController($scope, $mdDialog) {中时,如何为依赖提供引号?

1 个答案:

答案 0 :(得分:1)

尝试:

 $mdDialog.show({
    controller: ['$scope', '$mdDialog', DialogController]
    ...
  });

 function DialogController($scope, $mdDialog) {/* ...*/}

请注意,请避免在服务/工厂内部定义对话框。

相关问题