您好我是自定义指令
中隔离范围的新手这是我的指示
div.google-visualization-tooltip { display:none }
并在html中我只是将其包含为
restrict: 'E',
scope: {},
template: '<input type="file" ng-model="myFile" />{{myFile.name}}',
link: function(scope, element, attrs, sharedServices) {
var model = $parse(attrs.fileBrowser);
var modelSetter = model.assign;
element.bind("change", function(e) {
scope.fileForImagepreview = (e.srcElement || e.target).files[0];
if (scope.fileForImagepreview.type === "image/jpeg" ||
scope.fileForImagepreview.type === "image/jpg" ||
scope.fileForImagepreview.type === "image/png") {
scope.$apply(function() {
modelSetter(scope, element[0].firstChild.files[0]);
});
}
var promise = fileReader.readAsDataURL(scope.fileForImagepreview, scope);
promise.then(function(result) {
scope.imageSrcForPreview = result;
});
});
}
我希望文件在指令范围
答案 0 :(得分:1)
创建一个类似
的数组scope.imageSrcForPreview = [];
并将对象插入到数组中,因此我的函数看起来像。
var promise = fileReader.readAsDataURL(scope.fileForImagepreview, scope);
promise.then(function(result) {
scope.imageSrcForPreview.splice(index, 1, result);
scope.showPreview = true;
});