'错误:[$ injector:unpr]未知提供商'在Heroku上部署之后

时间:2016-03-15 16:53:17

标签: ruby-on-rails angularjs heroku

我的服务在开发环境中的loacal服务器上完美运行,但在生产中使用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协议?

1 个答案:

答案 0 :(得分:3)

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

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