2015-10-18 45 views
-1

我有這樣的角碼:

myApp.controller('en', [ '$scope', 'PDFViewerService', function($scope, pdf, $ionicLoading) { 

         console.log('en: new instance'); 

         $scope.pdfURL = "http://www.tafseer.info/phocadownload/copy_of_the_book/khatima.pdf";//fe.toURL(); 

         $scope.instance = pdf.Instance("viewer"); 

         $scope.nextPage = function() { 
          $scope.instance.nextPage(); 
         }; 

         $scope.prevPage = function() { 
          $scope.instance.prevPage(); 
         }; 

         $scope.gotoPage = function(page) { 
          $scope.instance.gotoPage(page); 
         }; 

         $scope.pageLoaded = function(curPage, totalPages) { 
          $scope.currentPage = curPage; 
          $scope.totalPages = totalPages; 
         }; 

         $scope.loadProgress = function(loaded, total, state) { 
          console.log('loaded =', loaded, 'total =', total, 'state =', state); 
         }; 
}]); 

而且在我的模板:

<button ng-click="prevPage()">&lt;</button> 
<button ng-click="nextPage()">&gt;</button> 
<br> 
<span>{{currentPage}}/{{totalPages}}</span> 
<br> 
<pdfviewer src="{{pdfURL}}" on-page-load='pageLoaded(page,total)' id="viewer"></pdfviewer> 

我試圖讓插入到我的網站上的PDF文件與AngularJS,但我不斷收到相同的錯誤:

Error: $interpolate:interr Interpolation Error 

爲什麼我得到這個錯誤,我該如何擺脫它?我要的只是插入PDF ...

+0

什麼是PDFViewerService和pdfviewer指令? –

+0

我使用這個https://github.com/akrennmair/ng-pdfviewer – AbuKotsh

回答

0

下面的代碼將依賴注入到控制器中是不正確的。

myApp.controller('en', [ '$scope', 'PDFViewerService', function($scope, pdf, $ionicLoading) { 

陣列中的依賴關係列表必須確切等於功能參數 正確的:

myApp.controller('en', [ '$scope', 'PDFViewerService', 'pdf', '$ionicLoading', function($scope, 'PDFViewerService', pdf, $ionicLoading) { 
+0

我嘗試你的代碼,但告訴我這個錯誤'未捕獲的SyntaxError:意外的字符串' – AbuKotsh

+0

這是因爲我列出的一個依賴項都存在於你的應用。我剛糾正了你的語法錯誤。確保所有PDFViewerService和pdf以及$ ionicLoading存在並定義。 –

+0

那麼哪裏出錯? – AbuKotsh

0

主要的問題是你在哪裏得到的PDF,這應該是在同一個起源(域)正常工作,而不是在遠程位置,您可以嘗試添加$sce.trustAsResourceUrl,但我認爲它不會足以工作:

app.controller('dummy', ['$scope', 'PDFViewerService', '$sce', function ($scope, pdf, $sce) { 

    $scope.pdfURL = $sce.trustAsResourceUrl("http://www.tafseer.info/phocadownload/copy_of_the_book/khatima.pdf"); //fe.toURL(); 

... 

我的建議是將PDF下載到本地目錄,並從那裏用pdfviewer打開。