Search code examples
javascriptangularjscoffeescriptangular-formly

Unknown provider: tProvider <- t


I get this error only on minified code (production). bug was created when I add 'controller' function inside formly.. Please look up my code, maybe you will see some bug.. Any tips will be useful ;)

Dependencies: "angular-formly": "~7.1.2", "angular-formly-templates-bootstrap": "~6.1.0",

My code of controller:

.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}"

    @
  )

Solution

  • you need to explicitly inject $rootScope:

    instead of ($rootScope) -> {code...}

    use

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

    Otherwise, the '$rootScope' dependency is implied from the variable name. As $rootScope becomes $t during your minification angular implies you want to inject '$t' which doesnt exist.

    google ng-annotate which automatically 'explicifies' your injections.

    edit: I'm not familiar with coffeescript, so please bear with me :)