Angularjs 角形罐';t从其他指令更改ng模型

Angularjs 角形罐';t从其他指令更改ng模型,angularjs,directive,angular-directive,Angularjs,Directive,Angular Directive,我需要更改pdfViewerToolbar指令中的ng模型(currentPage),方法是单击pdfViewer指令中的画布。当我单击画布时,会调用控制器中的self.next函数,但pdfViewerToolbar指令中的ng model=“currentPage”没有更改 app.angular.module(“pdf”)指令(“pdfViewerToolbar”,“pdfDelegate”,函数(e){ 返回{ 限制:“E”, 模板:'\ \ \ \ \ \ \ \ 页面\ \ {{p

我需要更改pdfViewerToolbar指令中的ng模型(currentPage),方法是单击pdfViewer指令中的画布。当我单击画布时,会调用控制器中的self.next函数,但pdfViewerToolbar指令中的ng model=“currentPage”没有更改

app.angular.module(“pdf”)指令(“pdfViewerToolbar”,“pdfDelegate”,函数(e){
返回{
限制:“E”,
模板:'\
\
\
\
\
\
\
\
页面\
\
{{pageCount}\
\
',
范围:{
页面计数:“=”,
导航栏:“=”,
},
//控制器:“PdfCtrl”,
链接:功能(t,n,a){
var o=a.delegateHandle;
t、 currentPage=1,t.prev=function(){
e、 $getByHandle(o.prev(),r()
},t.next=函数(){
e、 $getByHandle(o).next(),r()
},t.zoomIn=函数(){
e、 $getByHandle(o).zoomIn()
},t.zoomOut=函数(){
e、 $getByHandle(o).zoomOut()
},t.rotate=函数(){
e、 $getByHandle(o).rotate()
},t.goToPage=函数(){
e、 $getByHandle(o).goToPage(t.currentPage)
};
var r=函数(){
t、 currentPage=e.$getByHandle(o).getCurrentPage()
}
}
}
}])
应用程序角度模块(“pdf”)指令(“pdfViewer”[“pdfDelegate”),功能(r){
返回{
限制:“E”,
模板:“”,
范围:假,
控制器:“PdfCtrl”,
链接:功能(e、t、n){
e、 id=n.delegateHandle,e.showToolbar=e.$eval(n.showToolbar)| |!1
var o=n.delegateHandle;
e、 currentPage=1,
e、 下一步=函数(){
r、 $getByHandle(o).next(),s()
}
var s=函数(){
e、 currentPage=r.$getByHandle(o).getCurrentPage()
}
}
}
}]);
应用控制器('PdfCtrl'[
“$scope”,
“$element”,
“$attrs”,
“pdfDelegate”,
“$log”,
“$q”、“$rootScope”,
函数($scope、$element、$attrs、pdfDelegate、$log、$q、$rootScope){
//注册实例!
var deregisterInstance=pdfDelegate.\u registerInstance(此$attrs.delegateHandle);
//在毁灭上取消登记!
$scope.$on(“$destroy”,注销注册);
var self=这个;
var url=$scope.$eval($attrs.url);
var headers=$scope.$eval($attrs.headers);
var-pdfDoc;
$scope.pageCount=0;
var currentPage=1;
var角=0;
变量比例=$attrs.scale?$attrs.scale:1;
var canvas=$element.find('canvas')[0];
var ctx=canvas.getContext('2d');
self.next=函数(){
如果(当前页面>=pdfDoc.numPages)
返回;
currentPage=parseInt(currentPage,10)+1;
渲染页面(当前页面);
console.log('currentPage'+currentPage);
};
返回PDFJS
.getDocument(docInitParams)
.然后(函数(_pdfDoc){
console.log('loaded');
$rootScope.loadPdf=$scope.pdfNavigationBar=true;
pdfDoc=_pdfDoc;
渲染图(1);
$scope.$apply(函数(){
$scope.pageCount=\u pdfDoc.numPages;
});
},函数(错误){
$log.error(错误);
返回$q.reject(错误);
})
};
if(url)self.load();

}]);您需要将currentPage变量作为独立指令传递,如下所示

 return {
    restrict: "E",
    template: '<div  class="pdf_navigation" ng-show="navBar">\
        <div class="pdf_buttons">\
            <div ng-click="prev()" class="goPrevious" title="previous page"></div>\
            <div ng-click="next()" class="goNext" id="goNext" title="next page"></div>\
            <div ng-click="zoomOut()" class="zoomIn"></div>\
            <div ng-click="zoomIn()" class="zoomOut"></div>\
        </div>\
        <div class="pdf_page">\
            <span>Page</span>\
            <input type="text" min=1 ng-model="currentPage" maxlength="4" ng-change="goToPage()" >\
            <span>of {{pageCount}}</span>\
        </div>\
    </div>',
    scope: {
        pageCount: "=",
        navBar: "=",
        currentPage: "="
    },
    ...
    ...
    ...

您需要将currentPage变量作为独立指令传递,如下所示

 return {
    restrict: "E",
    template: '<div  class="pdf_navigation" ng-show="navBar">\
        <div class="pdf_buttons">\
            <div ng-click="prev()" class="goPrevious" title="previous page"></div>\
            <div ng-click="next()" class="goNext" id="goNext" title="next page"></div>\
            <div ng-click="zoomOut()" class="zoomIn"></div>\
            <div ng-click="zoomIn()" class="zoomOut"></div>\
        </div>\
        <div class="pdf_page">\
            <span>Page</span>\
            <input type="text" min=1 ng-model="currentPage" maxlength="4" ng-change="goToPage()" >\
            <span>of {{pageCount}}</span>\
        </div>\
    </div>',
    scope: {
        pageCount: "=",
        navBar: "=",
        currentPage: "="
    },
    ...
    ...
    ...

在您的
pdfViewerToolbar
指令中,
scope
是隔离的,如果您想更改该指令中的某些内容,您应该通过双向数据绑定将其作为scope元素传递:
“=”

并像这样使用您的指令传递控制器模型

<pdf-viewer-toolbar page-count="ctrlModelPageCount" nav-bar="ctrlModelNavBar" current-page="ctrlModelCurrentPage"></pdf-viewer-toolbar>


在您的
pdfViewerToolbar
指令
scope
是隔离的,如果您想更改该指令中的某些内容,您应该通过双向数据绑定将其作为scope元素传递:
“=”

并像这样使用您的指令传递控制器模型

<pdf-viewer-toolbar page-count="ctrlModelPageCount" nav-bar="ctrlModelNavBar" current-page="ctrlModelCurrentPage"></pdf-viewer-toolbar>

<pdf-viewer-toolbar page-count="ctrlModelPageCount" nav-bar="ctrlModelNavBar" current-page="ctrlModelCurrentPage"></pdf-viewer-toolbar>