Javascript 未知提供程序:tProvider<;-T

Javascript 未知提供程序:tProvider<;-T,javascript,angularjs,coffeescript,angular-formly,Javascript,Angularjs,Coffeescript,Angular Formly,我只有在缩小代码(生产)时才会出现此错误。 当我在formly中添加“controller”函数时,错误被创建。。 请查看我的代码,也许你会看到一些错误。。 任何提示都很有用;) 依赖项: “棱角形”:“~7.1.2”, “angular formly模板引导”:“~6.1.0” 我的控制器代码: .controller('NSearchBoxOnResultsController', ($rootScope) -> @formFields = [ ty

我只有在缩小代码(生产)时才会出现此错误。 当我在formly中添加“controller”函数时,错误被创建。。 请查看我的代码,也许你会看到一些错误。。 任何提示都很有用;)

依赖项: “棱角形”:“~7.1.2”, “angular formly模板引导”:“~6.1.0”

我的控制器代码:

.controller('NSearchBoxOnResultsController', ($rootScope) ->
    @formFields =
      [
        type: 'form_with_own_classes'
        key: 'q'
        defaultValue: @resultAsValue
        templateOptions:
          type: 'string'
          label: ''
          placeholder: I18n.t('homepage.placeholder')
          wrapper_class: 'row input--primary modal__center-items search search_query'
          input_container_class: 'col-xs-12'
          onKeypress: ($viewValue, $modelValue, scope, event) =>
            if event?.which == 13
              @submit()
        controller: ($scope, $rootScope) =>
          @scope = $scope
          @rootScope = $rootScope
          @rootScope.$on('$locationChangeSuccess', (newValue, oldValue) =>
            if @scope.options?.formControl
              @hash = window.location.hash.split('/')
              @queryFromHash = @hash.slice(2, @hash.length).join('/')
              @resultAsValue = decodeURIComponent(@queryFromHash)
              @scope.options.formControl.$setViewValue(@resultAsValue)
              @scope.options.formControl.$rollbackViewValue()
          )
      ]

    @submit = =>
      window.location = "/search/#all/#{@search.q}"

    @
  )

您需要显式注入$rootScope:

而不是
($rootScope)->{code…}

使用

['$rootScope',($rootScope)->{code…}]

否则,变量名将隐含“$rootScope”依赖项。当$rootScope在缩小过程中变为$t时,意味着您希望注入不存在的“$t”

谷歌ng注释,自动“明确”你的注射


编辑:我不熟悉coffeescript,所以请耐心听我说:)

但是当我没有在主控制器中注入$rootScope时,它也会正常工作-但同样的错误。我认为主控制器中的注入不会改变任何东西。
控制器:['$scope','$rootScope',($scope,$rootScope)=>{}]
。你真的应该查一下ng注释。它会帮你处理好的。这里有好的方法,也有坏的方法。我在使用Webpack缩小角度清理时遇到了这个错误。但是在
ngapp
-元素中使用strictmode:
ngStrictDi
,修复了错误。我在JS:
.controller('GoodController2',GoodController2'中使用了这样的控制器;函数GoodController2($scope){$scope.name='World';}GoodController2.$inject=['$scope']&