CdkDragAndDrop how to prevent dragging










0















I'm trying to use the Angular Material CDK DragDrop module from https://material.angular.io/cdk/drag-drop/overview



With the cdkDropListDropped event I can prevent dropping but it shouldn't be dragged either. How can I tell a cdkDropList or each cdkDrag elements to disable dragging?



<div class="list-group" id="orderlist" cdkDropList (cdkDropListDropped)="drop($event)">
<a class="list-group-item"
[class.linked]="ord.linkedToPrevious"
[class.selected]="ord.selected"
*ngFor="let ord of items" (click)="selectOrder(ord, $event)" cdkDrag>
<button class="btn btn-default btn-link linkeditem" [class.linked]="ord.linkedToPrevious"
(click)="linkTechnology(ord, $event)"
[attr.disabled]="editing ? null : true">
<span class="glyphicon glyphicon-link"></span>
</button>
<h4>ord.technology.name</h4>
</a>
</div>









share|improve this question


























    0















    I'm trying to use the Angular Material CDK DragDrop module from https://material.angular.io/cdk/drag-drop/overview



    With the cdkDropListDropped event I can prevent dropping but it shouldn't be dragged either. How can I tell a cdkDropList or each cdkDrag elements to disable dragging?



    <div class="list-group" id="orderlist" cdkDropList (cdkDropListDropped)="drop($event)">
    <a class="list-group-item"
    [class.linked]="ord.linkedToPrevious"
    [class.selected]="ord.selected"
    *ngFor="let ord of items" (click)="selectOrder(ord, $event)" cdkDrag>
    <button class="btn btn-default btn-link linkeditem" [class.linked]="ord.linkedToPrevious"
    (click)="linkTechnology(ord, $event)"
    [attr.disabled]="editing ? null : true">
    <span class="glyphicon glyphicon-link"></span>
    </button>
    <h4>ord.technology.name</h4>
    </a>
    </div>









    share|improve this question
























      0












      0








      0








      I'm trying to use the Angular Material CDK DragDrop module from https://material.angular.io/cdk/drag-drop/overview



      With the cdkDropListDropped event I can prevent dropping but it shouldn't be dragged either. How can I tell a cdkDropList or each cdkDrag elements to disable dragging?



      <div class="list-group" id="orderlist" cdkDropList (cdkDropListDropped)="drop($event)">
      <a class="list-group-item"
      [class.linked]="ord.linkedToPrevious"
      [class.selected]="ord.selected"
      *ngFor="let ord of items" (click)="selectOrder(ord, $event)" cdkDrag>
      <button class="btn btn-default btn-link linkeditem" [class.linked]="ord.linkedToPrevious"
      (click)="linkTechnology(ord, $event)"
      [attr.disabled]="editing ? null : true">
      <span class="glyphicon glyphicon-link"></span>
      </button>
      <h4>ord.technology.name</h4>
      </a>
      </div>









      share|improve this question














      I'm trying to use the Angular Material CDK DragDrop module from https://material.angular.io/cdk/drag-drop/overview



      With the cdkDropListDropped event I can prevent dropping but it shouldn't be dragged either. How can I tell a cdkDropList or each cdkDrag elements to disable dragging?



      <div class="list-group" id="orderlist" cdkDropList (cdkDropListDropped)="drop($event)">
      <a class="list-group-item"
      [class.linked]="ord.linkedToPrevious"
      [class.selected]="ord.selected"
      *ngFor="let ord of items" (click)="selectOrder(ord, $event)" cdkDrag>
      <button class="btn btn-default btn-link linkeditem" [class.linked]="ord.linkedToPrevious"
      (click)="linkTechnology(ord, $event)"
      [attr.disabled]="editing ? null : true">
      <span class="glyphicon glyphicon-link"></span>
      </button>
      <h4>ord.technology.name</h4>
      </a>
      </div>






      angular angular-material angular-cdk






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 13 '18 at 11:16









      PerrierPerrier

      9142930




      9142930






















          3 Answers
          3






          active

          oldest

          votes


















          1














          You can use cdkDragHandle with Property binding with “class” some property like on or off something like toggle.



          <div class="example-handle" [class.your-css-class]="!editing" cdkDragHandle>
          <svg width="24px" fill="currentColor" viewBox="0 0 24 24">
          <path d="M10 9h4V6h3l-5-5-5 5h3v3zm-1 1H6V7l-5 5 5 5v-3h3v-4zm14 2l-5-5v3h-3v4h3v3l5-5zm-9 3h-4v3H7l5 5 5-5h-3v-3z"></path>
          <path d="M0 0h24v24H0z" fill="none"></path>
          </svg>




          .your-css-class
          display: none






          share|improve this answer

























          • ngIf="false" will not work because it completely removes the element which means the cdkDrag element won't have a draghandle so the complete element will be draggable.

            – Perrier
            Nov 13 '18 at 12:08






          • 1





            In that case, just [style.display]="someProperty ? 'none' : 'block' " , it will hide it and also user will not able to drag.

            – Narendra Singh Rathore
            Nov 13 '18 at 12:09












          • It has worked, thanks! Would you like to edit your solution? I have used [class.display-none]="!editing" on cdkDragHandle.

            – Perrier
            Nov 13 '18 at 12:15











          • Yes, i had updated the answer, you can mark it answer and up vote if useful.

            – Narendra Singh Rathore
            Nov 13 '18 at 12:20


















          1














          Disable dragging
          If you want to disable dragging for a particular drag item, you can do so by setting the cdkDragDisabled input on a cdkDrag item. Furthermore, you can disable an entire list using the cdkDropListDisabled input on a cdkDropList or a particular handle via cdkDragHandleDisabled on cdkDragHandle.



          <div cdkDropList class="example-list" (cdkDropListDropped)="drop($event)">
          <div
          class="example-box"
          *ngFor="let item of items"
          cdkDrag
          [cdkDragDisabled]="item.disabled">item.value</div>
          </div>





          share|improve this answer






























            0














            If you want to disable dragging for a particular drag item, you can do so by setting the cdkDragDisabled input on a cdkDrag item.



            <div cdkDropList class="list" (cdkDropListDropped)="drop($event)">
            <div *ngFor="let item of dragedItems" cdkDrag
            [cdkDragDisabled]="item.disabled"> item.value </div>
            </div>


            Reference: https://github.com/angular/material2/blob/master/src/material-examples/cdk-drag-drop-disabled/cdk-drag-drop-disabled-example.html



            https://github.com/angular/material2/pull/13722/commits/bd56a49dda5b5d2f0f0f2feac829afbe3752f5d5






            share|improve this answer






















              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53279829%2fcdkdraganddrop-how-to-prevent-dragging%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              1














              You can use cdkDragHandle with Property binding with “class” some property like on or off something like toggle.



              <div class="example-handle" [class.your-css-class]="!editing" cdkDragHandle>
              <svg width="24px" fill="currentColor" viewBox="0 0 24 24">
              <path d="M10 9h4V6h3l-5-5-5 5h3v3zm-1 1H6V7l-5 5 5 5v-3h3v-4zm14 2l-5-5v3h-3v4h3v3l5-5zm-9 3h-4v3H7l5 5 5-5h-3v-3z"></path>
              <path d="M0 0h24v24H0z" fill="none"></path>
              </svg>




              .your-css-class
              display: none






              share|improve this answer

























              • ngIf="false" will not work because it completely removes the element which means the cdkDrag element won't have a draghandle so the complete element will be draggable.

                – Perrier
                Nov 13 '18 at 12:08






              • 1





                In that case, just [style.display]="someProperty ? 'none' : 'block' " , it will hide it and also user will not able to drag.

                – Narendra Singh Rathore
                Nov 13 '18 at 12:09












              • It has worked, thanks! Would you like to edit your solution? I have used [class.display-none]="!editing" on cdkDragHandle.

                – Perrier
                Nov 13 '18 at 12:15











              • Yes, i had updated the answer, you can mark it answer and up vote if useful.

                – Narendra Singh Rathore
                Nov 13 '18 at 12:20















              1














              You can use cdkDragHandle with Property binding with “class” some property like on or off something like toggle.



              <div class="example-handle" [class.your-css-class]="!editing" cdkDragHandle>
              <svg width="24px" fill="currentColor" viewBox="0 0 24 24">
              <path d="M10 9h4V6h3l-5-5-5 5h3v3zm-1 1H6V7l-5 5 5 5v-3h3v-4zm14 2l-5-5v3h-3v4h3v3l5-5zm-9 3h-4v3H7l5 5 5-5h-3v-3z"></path>
              <path d="M0 0h24v24H0z" fill="none"></path>
              </svg>




              .your-css-class
              display: none






              share|improve this answer

























              • ngIf="false" will not work because it completely removes the element which means the cdkDrag element won't have a draghandle so the complete element will be draggable.

                – Perrier
                Nov 13 '18 at 12:08






              • 1





                In that case, just [style.display]="someProperty ? 'none' : 'block' " , it will hide it and also user will not able to drag.

                – Narendra Singh Rathore
                Nov 13 '18 at 12:09












              • It has worked, thanks! Would you like to edit your solution? I have used [class.display-none]="!editing" on cdkDragHandle.

                – Perrier
                Nov 13 '18 at 12:15











              • Yes, i had updated the answer, you can mark it answer and up vote if useful.

                – Narendra Singh Rathore
                Nov 13 '18 at 12:20













              1












              1








              1







              You can use cdkDragHandle with Property binding with “class” some property like on or off something like toggle.



              <div class="example-handle" [class.your-css-class]="!editing" cdkDragHandle>
              <svg width="24px" fill="currentColor" viewBox="0 0 24 24">
              <path d="M10 9h4V6h3l-5-5-5 5h3v3zm-1 1H6V7l-5 5 5 5v-3h3v-4zm14 2l-5-5v3h-3v4h3v3l5-5zm-9 3h-4v3H7l5 5 5-5h-3v-3z"></path>
              <path d="M0 0h24v24H0z" fill="none"></path>
              </svg>




              .your-css-class
              display: none






              share|improve this answer















              You can use cdkDragHandle with Property binding with “class” some property like on or off something like toggle.



              <div class="example-handle" [class.your-css-class]="!editing" cdkDragHandle>
              <svg width="24px" fill="currentColor" viewBox="0 0 24 24">
              <path d="M10 9h4V6h3l-5-5-5 5h3v3zm-1 1H6V7l-5 5 5 5v-3h3v-4zm14 2l-5-5v3h-3v4h3v3l5-5zm-9 3h-4v3H7l5 5 5-5h-3v-3z"></path>
              <path d="M0 0h24v24H0z" fill="none"></path>
              </svg>




              .your-css-class
              display: none







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Nov 13 '18 at 12:19

























              answered Nov 13 '18 at 11:29









              Narendra Singh RathoreNarendra Singh Rathore

              1992418




              1992418












              • ngIf="false" will not work because it completely removes the element which means the cdkDrag element won't have a draghandle so the complete element will be draggable.

                – Perrier
                Nov 13 '18 at 12:08






              • 1





                In that case, just [style.display]="someProperty ? 'none' : 'block' " , it will hide it and also user will not able to drag.

                – Narendra Singh Rathore
                Nov 13 '18 at 12:09












              • It has worked, thanks! Would you like to edit your solution? I have used [class.display-none]="!editing" on cdkDragHandle.

                – Perrier
                Nov 13 '18 at 12:15











              • Yes, i had updated the answer, you can mark it answer and up vote if useful.

                – Narendra Singh Rathore
                Nov 13 '18 at 12:20

















              • ngIf="false" will not work because it completely removes the element which means the cdkDrag element won't have a draghandle so the complete element will be draggable.

                – Perrier
                Nov 13 '18 at 12:08






              • 1





                In that case, just [style.display]="someProperty ? 'none' : 'block' " , it will hide it and also user will not able to drag.

                – Narendra Singh Rathore
                Nov 13 '18 at 12:09












              • It has worked, thanks! Would you like to edit your solution? I have used [class.display-none]="!editing" on cdkDragHandle.

                – Perrier
                Nov 13 '18 at 12:15











              • Yes, i had updated the answer, you can mark it answer and up vote if useful.

                – Narendra Singh Rathore
                Nov 13 '18 at 12:20
















              ngIf="false" will not work because it completely removes the element which means the cdkDrag element won't have a draghandle so the complete element will be draggable.

              – Perrier
              Nov 13 '18 at 12:08





              ngIf="false" will not work because it completely removes the element which means the cdkDrag element won't have a draghandle so the complete element will be draggable.

              – Perrier
              Nov 13 '18 at 12:08




              1




              1





              In that case, just [style.display]="someProperty ? 'none' : 'block' " , it will hide it and also user will not able to drag.

              – Narendra Singh Rathore
              Nov 13 '18 at 12:09






              In that case, just [style.display]="someProperty ? 'none' : 'block' " , it will hide it and also user will not able to drag.

              – Narendra Singh Rathore
              Nov 13 '18 at 12:09














              It has worked, thanks! Would you like to edit your solution? I have used [class.display-none]="!editing" on cdkDragHandle.

              – Perrier
              Nov 13 '18 at 12:15





              It has worked, thanks! Would you like to edit your solution? I have used [class.display-none]="!editing" on cdkDragHandle.

              – Perrier
              Nov 13 '18 at 12:15













              Yes, i had updated the answer, you can mark it answer and up vote if useful.

              – Narendra Singh Rathore
              Nov 13 '18 at 12:20





              Yes, i had updated the answer, you can mark it answer and up vote if useful.

              – Narendra Singh Rathore
              Nov 13 '18 at 12:20













              1














              Disable dragging
              If you want to disable dragging for a particular drag item, you can do so by setting the cdkDragDisabled input on a cdkDrag item. Furthermore, you can disable an entire list using the cdkDropListDisabled input on a cdkDropList or a particular handle via cdkDragHandleDisabled on cdkDragHandle.



              <div cdkDropList class="example-list" (cdkDropListDropped)="drop($event)">
              <div
              class="example-box"
              *ngFor="let item of items"
              cdkDrag
              [cdkDragDisabled]="item.disabled">item.value</div>
              </div>





              share|improve this answer



























                1














                Disable dragging
                If you want to disable dragging for a particular drag item, you can do so by setting the cdkDragDisabled input on a cdkDrag item. Furthermore, you can disable an entire list using the cdkDropListDisabled input on a cdkDropList or a particular handle via cdkDragHandleDisabled on cdkDragHandle.



                <div cdkDropList class="example-list" (cdkDropListDropped)="drop($event)">
                <div
                class="example-box"
                *ngFor="let item of items"
                cdkDrag
                [cdkDragDisabled]="item.disabled">item.value</div>
                </div>





                share|improve this answer

























                  1












                  1








                  1







                  Disable dragging
                  If you want to disable dragging for a particular drag item, you can do so by setting the cdkDragDisabled input on a cdkDrag item. Furthermore, you can disable an entire list using the cdkDropListDisabled input on a cdkDropList or a particular handle via cdkDragHandleDisabled on cdkDragHandle.



                  <div cdkDropList class="example-list" (cdkDropListDropped)="drop($event)">
                  <div
                  class="example-box"
                  *ngFor="let item of items"
                  cdkDrag
                  [cdkDragDisabled]="item.disabled">item.value</div>
                  </div>





                  share|improve this answer













                  Disable dragging
                  If you want to disable dragging for a particular drag item, you can do so by setting the cdkDragDisabled input on a cdkDrag item. Furthermore, you can disable an entire list using the cdkDropListDisabled input on a cdkDropList or a particular handle via cdkDragHandleDisabled on cdkDragHandle.



                  <div cdkDropList class="example-list" (cdkDropListDropped)="drop($event)">
                  <div
                  class="example-box"
                  *ngFor="let item of items"
                  cdkDrag
                  [cdkDragDisabled]="item.disabled">item.value</div>
                  </div>






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jan 14 at 10:53









                  Me SaMe Sa

                  112




                  112





















                      0














                      If you want to disable dragging for a particular drag item, you can do so by setting the cdkDragDisabled input on a cdkDrag item.



                      <div cdkDropList class="list" (cdkDropListDropped)="drop($event)">
                      <div *ngFor="let item of dragedItems" cdkDrag
                      [cdkDragDisabled]="item.disabled"> item.value </div>
                      </div>


                      Reference: https://github.com/angular/material2/blob/master/src/material-examples/cdk-drag-drop-disabled/cdk-drag-drop-disabled-example.html



                      https://github.com/angular/material2/pull/13722/commits/bd56a49dda5b5d2f0f0f2feac829afbe3752f5d5






                      share|improve this answer



























                        0














                        If you want to disable dragging for a particular drag item, you can do so by setting the cdkDragDisabled input on a cdkDrag item.



                        <div cdkDropList class="list" (cdkDropListDropped)="drop($event)">
                        <div *ngFor="let item of dragedItems" cdkDrag
                        [cdkDragDisabled]="item.disabled"> item.value </div>
                        </div>


                        Reference: https://github.com/angular/material2/blob/master/src/material-examples/cdk-drag-drop-disabled/cdk-drag-drop-disabled-example.html



                        https://github.com/angular/material2/pull/13722/commits/bd56a49dda5b5d2f0f0f2feac829afbe3752f5d5






                        share|improve this answer

























                          0












                          0








                          0







                          If you want to disable dragging for a particular drag item, you can do so by setting the cdkDragDisabled input on a cdkDrag item.



                          <div cdkDropList class="list" (cdkDropListDropped)="drop($event)">
                          <div *ngFor="let item of dragedItems" cdkDrag
                          [cdkDragDisabled]="item.disabled"> item.value </div>
                          </div>


                          Reference: https://github.com/angular/material2/blob/master/src/material-examples/cdk-drag-drop-disabled/cdk-drag-drop-disabled-example.html



                          https://github.com/angular/material2/pull/13722/commits/bd56a49dda5b5d2f0f0f2feac829afbe3752f5d5






                          share|improve this answer













                          If you want to disable dragging for a particular drag item, you can do so by setting the cdkDragDisabled input on a cdkDrag item.



                          <div cdkDropList class="list" (cdkDropListDropped)="drop($event)">
                          <div *ngFor="let item of dragedItems" cdkDrag
                          [cdkDragDisabled]="item.disabled"> item.value </div>
                          </div>


                          Reference: https://github.com/angular/material2/blob/master/src/material-examples/cdk-drag-drop-disabled/cdk-drag-drop-disabled-example.html



                          https://github.com/angular/material2/pull/13722/commits/bd56a49dda5b5d2f0f0f2feac829afbe3752f5d5







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Jan 7 at 13:43









                          Mohd. ShariqMohd. Shariq

                          6429




                          6429



























                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53279829%2fcdkdraganddrop-how-to-prevent-dragging%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              這個網誌中的熱門文章

                              What does pagestruct do in Eviews?

                              Dutch intervention in Lombok and Karangasem

                              Channel Islands