2016-03-15 110 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

相關問題