2015-10-18 84 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打开。