angular2-draggable icon indicating copy to clipboard operation
angular2-draggable copied to clipboard

dragging is not working for ng-template

Open ghost opened this issue 8 years ago • 5 comments

Hi I'm using NgbModal in Angular4 application. for that modal popup drag and drop, we are using angular2-draggable. it is working fine for simple "div" and it is not working as expected with ng-template

here is my sample code <ng-template #divBranching let-c="close" let-d="dismiss"> <div ngDraggable [handle]="divDraggable" class="card" style="resize: both; overflow:hidden"> <div #divDraggable class="card-header"> <h3>Draggable Content</h3> </div> </div> </ng-template> angular2-draggable issue parent items is displaying in the same position. if i apply ngDraggable and [handle] to the ng-template we are unable to drag it. please help to fix this issue

ghost avatar Nov 01 '17 09:11 ghost

@SivaPrakashK90 I'm afraid it's not an issue of this directive. In your code, #divDraggable is not the parent element. In fact, NgbModal will create a 'modal-content' to contain ng-template. So if you can find a way to get correct templateRef of the parent element, you can make it work.

xieziyu avatar Nov 01 '17 14:11 xieziyu

can you provide me working example?

ghost avatar Nov 03 '17 14:11 ghost

@SivaPrakashK90, here is what i do. // i have 2 modal-content in my modal, the first one is the container as xieziyu said. const aa = document.getElementsByClassName('modal-content'); // set the first modal-content white and transparent aa[0].setAttribute('style','background-color: rgba(255,255,255,0)'); // set the second one not transparent aa[1].setAttribute('style','opacity: 1');

but the border still seen, i'm working on it.

FreeZaaa avatar Dec 29 '17 01:12 FreeZaaa

@SivaPrakashK90 const aa = document.getElementsByClassName('modal-content'); aa[0].setAttribute('style', 'background-color: rgba(255,255,255,0);border:rgba(255, 255, 255, 0)'); aa[1].setAttribute('style', 'opacity: 1');

FreeZaaa avatar Dec 29 '17 02:12 FreeZaaa

my idea:

<ng-template #modaltemplate>
   <div ngDraggable class="modal-draggable"> //after ng-template you create a div so you can add ngDraggable attribute and class modal-draggable
     // bootstrap modal head body footer goes here
   </div>
 </ng-template>

In component.ts you add this to open bootstrap.

the object is to add class to the modal-dialog

this.modalRef = this.modalService.show(modaltemplate, {class: 'backgroundTransparent'});

In component.css you add this css codes.

below code, we will set background and border-radius to modal-draggable

.modal-content > .modal-draggable {
	background-color: #fff;
	border-radius: 6px;
}

before we added style to modal-content, the result is like this

screenshot 2019-01-30 at 9 14 23 am

after we added style to modal-content

screenshot 2019-01-30 at 9 14 50 am
.backgroundTransparent .modal-content {
	background: transparent;
	border: 0;
}

hope this help.

faizal,

faizaldong avatar Jan 30 '19 01:01 faizaldong