您的位置:首页 > Web前端 > AngularJS

Angularjs 指令示例

2016-06-28 15:01 489 查看
pdf文件预览指令

1.指令定义

app.directive('embedPdf', function() {
return {
restrict: 'E',
scope: {
attachment: '=attachment'
},
template:'',
link: function(scope, element, attrs) {
function showAttachment(attachment) {
if (!attachment) {
element.html('<div align="center">文件不存在。</div>');
}else if(!(attachment.mimeType == 'application/pdf')){
element.html('<div align="center"><h3>文件不是PDF格式文件,无法预览。</h3></div>');
}else if(attachment.mimeType == 'application/pdf'){
element.html('<embed width="850px" height="495px" src="' + app.contextPath + '/attachments/file/' + attachment.name + '" type="application/pdf"></embed>');
}
}
scope.$watch('attachment', function(nv, ov) {
showAttachment(nv);
});
showAttachment(scope.attachment);
}
};
});


2.js代码

$scope.view = function(id){
jddoclstRes.findAttach({'attId':id},{},function(r){
$scope.attachment = r;
});
$scope.viewDlg.visible = true;
}


3.指令使用

<embed-pdf attachment="attachment"/>


4.命名规则

<embed-pdf/>~~对应'embedPdf'
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  angularjs pdf