【问题标题】:Unknown provider: eProvider <- e未知提供者:eProvider <- e
【发布时间】:2020-10-05 21:45:31
【问题描述】:

我正在更新旧版 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) { 中时,如何在依赖项周围提供引号?

【问题讨论】:

    标签: angularjs


    【解决方案1】:

    试试:

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

    附带说明,请避免在服务/工厂中定义对话框。

    【讨论】:

      猜你喜欢
      • 2016-01-11
      • 2017-04-28
      • 2014-10-25
      • 2016-05-09
      • 2015-06-18
      • 2016-04-02
      • 2012-11-07
      • 1970-01-01
      • 2013-09-27
      相关资源
      最近更新 更多