在 Heroku 上部署后的'Error: [$injector:unpr] Unknown provider'



我有一个服务,可以在开发环境中的 loacal 服务器上完美运行,但在生产环境中的 Heroku 上,我收到错误[$injector:unpr] Unknown provider: tProvider <- t <- SidebarService <- sidebarDirective

咖啡脚本:

app.factory 'SidebarService', ($http) ->
  Resource = {}
  Resource.getAllPhotos = () ->
    $http.get('/photos.json')
  Resource.getAlbum = () ->
    $http.get()

  Resource
app.directive 'sidebar', ['SidebarService', (SidebarService) ->
  template = ''
  initSideBar = (s, e, a) ->
    $(document).on 'click', '#all-photos', ->
      SidebarService.getAllPhotos().then (result) ->
        d = result.data
        pics = for n, pic of d
          "<div class='draggable slider__picture' id='photo-#{n}' data-type='picture' data-source='#{pic.original}' style='background: url(#{pic.thumb}) center / cover'></div>"
        template = "<div class='slider__button-back' id='button-back__all-photos'><i class='material-icons'>arrow_back</i>" +
            "<span>Back</span></div>" +
            pics.join ''
        $('#slider-pictures').empty().removeClass('slider-pictures')
        $('#slider-pictures').append(template)
        $('.draggable').draggable(
          {
            revert: true
            appendTo: 'body'
            containment: 'window'
            scroll: false
            zIndex: 100
            helper: 'clone'
          })
  return {
    restrict: 'E',
    template: template,
    scope: {},
    link: (scope, element, attributes) ->
      initSideBar(scope, element, attributes)
    }
]

我应该在哪里挖掘?也许是因为https Heroku的协议?

请记住,资产(特别是在这种情况下为 js)在开发时不会缩小,而在生产中它们会被缩小。这些错误可能是由 js 缩小期间的冲突引起的。为避免在缩小过程中出现"$injector类型的错误,请确保使用 $inject 手动识别 Angular 组件的依赖项。

看看这里,完整的推荐/练习 https://github.com/johnpapa/angular-styleguide/blob/master/a1/README.md#style-y091

最新更新