【问题标题】:'Error: [$injector:unpr] Unknown provider' after deploying on Heroku在 Heroku 上部署后出现“错误:[$injector:unpr] 未知提供者”
【发布时间】:2016-10-12 21:02:42
【问题描述】:

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

CoffeeScript:

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)
    }
]

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

【问题讨论】:

  • 在我看来,您的应用未能找到 sidebarDirective 指令。确保包含该指令的 JS 文件已加载到 app html 文件中。

标签: ruby-on-rails angularjs heroku


【解决方案1】:

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

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

【讨论】:

  • 注射没有帮助
猜你喜欢
  • 2014-10-25
  • 2017-04-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-01-25
  • 2016-03-26
  • 2014-07-19
  • 1970-01-01
相关资源
最近更新 更多