2016-03-15 114 views
2

部署后,我有一个完美的作品我在开发环境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协议?

+0

看来,我认为你的应用程序未能位于'sidebarDirective'指令。确保包含此指令的JS文件已加载到应用程序html文件中。 –

回答

3

记住资产(特别是本例中的js)在开发过程中没有被缩小,而是在产品中被缩小。这些错误可能是由js缩小期间的冲突引起的。为了避免在缩小过程中出现$注入类型的错误,请确保使用$ inject手动标识对Angular组件的依赖关系。

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

+0

注射没有帮助 – Viktor

相关问题