os-image-uploader
지시어를 작성하여 이미지를 업로드 한 다음 편집하여 내 서버에 업로드하십시오.모든 인스턴스에서 AngularJS 지시문 이벤트 리스너가 실행됩니다.
(function(angular) {
'use strict';
angular
.module('AwareClientApp')
.directive('osImageUploader', function() {
return {
restrict: 'E',
templateUrl: 'scripts/components/os-image-uploader/os-image-uploader.html',
scope: {
selectionHeight: '@',
selectionWidth: '@',
width: '@',
height: '@',
url: '@',
imageId: '@',
type: '@',
image: '='
},
controllerAs: 'osImage',
controller: imageUploaderController,
link: function(scope, element) {
var input = element.find('#image_upload');
element.on('click', function (e) {
console.log(e);
console.log('clicked');
console.log(scope);
console.log(element);
});
function readFile =() {
if (scope.input[0].files && scope.input[0].files[0]) {
var filereader = new FileReader();
filereader.onload = function(e) {
scope.image.imageData = e.target.result;
scope.$root.$apply();
};
filereader.readAsDataURL(scope.input[0].files[0]);
}
}
input.addEventListener('change', readFile);
}
};
});
:
<label for="image_upload" class="image-upload-button"><span>Choose an image</span></label>
<input type="file" name="image_upload" id="image_upload" accept=".gif, .jpg, .png">
<image-editor id="image" ng-if="image.imageData.length > 0" image="{{image.imageData}}" selection-width="{{selectionWidth}}" selection-height="{{selectionHeight}}" width="{{width}}" height="{{height}}" controls="osImage.controls" state="image.state"></image-editor>
여기 내 지시어입니다 (이미지 편집기가 내가 말할 수있는 문제가 발생하지 않는 중첩 된 지침이) : 여기
템플릿입니다지시어의 파일 입력에 이벤트 리스너를 연결하는 링크 함수가 있습니다. 나는 그것을 구축하고 테스트했습니다 동안 만 HTML에서의 하나 개의 인스턴스가있을 때 그것은 좋은 일해
그러나
<md-content class="md-padding input-tab-content images-edit" ng-if="!tabImages.isDisabled">
<div class="header">
<h1>Header</h1>
<div layout="row" layout-sm="column" layout-align="space-around" ng-if="tabImages.loadingHeaderImage">
<md-progress-circular class="md-primary" md-diameter="60px" md-mode='indeterminate'>
</md-progress-circular>
</div>
<div class="header-image-container">
<img ng-src="{{tabImages.images.header.url}}" style="top: {{tabImages.images.header.newCrop.top}}px; left: {{tabImages.images.header.newCrop.left}}px; width: {{tabImages.images.header.newCrop.width}}px;" alt="header-image" class="header-image"/>
</div>
<h4>header url: {{tabImages.images.header.url}}</h4>
<os-image-uploader selection-width="400" selection-height="196" width="400" height="196" image-id="{{tabImages.images.header.id}}" type="header" image="tabImages.imageReference.header" input="tabImages.imageReference.header.input"></os-image-uploader>
</div>
</md-content>
, 나는 로고 이미지에 대한 또 다른 섹션을 추가하는 데 필요한 같은 페이지. 문제는, 더 중요한 것은, 변경 이벤트 (나는 이것을 테스트하기 위해 사용되었는지)와 클릭 이벤트들이 별도의 범위를 가지고 있으며 비록 두 요소에 발사한다는 것이다
<md-content class="md-padding input-tab-content images-edit" ng-if="!tabImages.isDisabled">
<div class="logo">
<h1>Logo</h1>
<div layout="row" layout-sm="column" layout-align="space-around" ng-if="tabImages.loadingLogoImage">
<md-progress-circular class="md-primary" md-diameter="60px" md-mode='indeterminate'>
</md-progress-circular>
</div>
<div class="logo-image-container">
<img ng-src="{{tabImages.images.logo.url}}" style="" alt="logo-image" class="logo-image"/>
</div>
<h4>logo url: {{tabImages.images.logo.url}}</h4>
<os-image-uploader selection-width="400" selection-height="88" width="400" height="88" image-id="{{tabImages.images.logo.id}}" type="logo" image="tabImages.imageReference.logo" input="tabImages.imageReference.logo.input"></os-image-uploader>
</div>
<div class="header">
<h1>Header</h1>
<div layout="row" layout-sm="column" layout-align="space-around" ng-if="tabImages.loadingHeaderImage">
<md-progress-circular class="md-primary" md-diameter="60px" md-mode='indeterminate'>
</md-progress-circular>
</div>
<div class="header-image-container">
<img ng-src="{{tabImages.images.header.url}}" style="top: {{tabImages.images.header.newCrop.top}}px; left: {{tabImages.images.header.newCrop.left}}px; width: {{tabImages.images.header.newCrop.width}}px;" alt="header-image" class="header-image"/>
</div>
<h4>header url: {{tabImages.images.header.url}}</h4>
<os-image-uploader selection-width="400" selection-height="196" width="400" height="196" image-id="{{tabImages.images.header.id}}" type="header" image="tabImages.imageReference.header" input="tabImages.imageReference.header.input"></os-image-uploader>
</div>
</md-content>
: 그래서 내가 그랬어 이벤트가 바인드 된 요소는 각각의 지시문에 있습니다.
이 클릭 이벤트 (확실하지가 도움이 얼마나 많은)에 대한콘솔 로그 :
os-image-uploader.js:46 j…y.Event {originalEvent: MouseEvent, type: "click", timeStamp: 8562.660000000002, jQuery2240034688928910062033: true, toElement: label.image-upload-button…}
os-image-uploader.js:49 clicked
os-image-uploader.js:50 Scope {$id: 837, $$childTail: null, $$childHead: null, $$prevSibling: Scope, $$nextSibling: null…}
os-image-uploader.js:51 [os-image-uploader.ng-isolate-scope, context: os-image-uploader.ng-isolate-scope]
os-image-uploader.js:46 j…y.Event {originalEvent: MouseEvent, type: "click", timeStamp: 8562.660000000002, jQuery2240034688928910062033: true, toElement: input#image_upload…}
os-image-uploader.js:49 clicked
os-image-uploader.js:50 Scope {$id: 836, $$childTail: null, $$childHead: null, $$prevSibling: null, $$nextSibling: Scope…}
os-image-uploader.js:51 [os-image-uploader.ng-isolate-scope, context: os-image-uploader.ng-isolate-scope]
내가 잘못 여기서 뭐하는 거지? 나는 이것에 대해 며칠 동안 일해 왔으며, 내가 놓친 바보 같은 것이 아니라기를 정말로 바랍니다.
어떻게하면 클릭 이벤트가 발생하나요?! –