Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

mdChip : onDelete event on Chips #3190

Closed
tagazok opened this issue Jun 9, 2015 · 7 comments
Closed

mdChip : onDelete event on Chips #3190

tagazok opened this issue Jun 9, 2015 · 7 comments
Assignees
Labels
pr: merge ready This PR is ready for a caretaker to review
Milestone

Comments

@tagazok
Copy link

tagazok commented Jun 9, 2015

Hi,
I have noticed there is a parameter onAppend parameter to the Chips component allowing me to know when a new element is added.
However, I can't see any way to get notified when an element is deleted from the Chips.
Would it be possible to have a similar parameter to be able to know when an element has been removed ?

@tagazok tagazok changed the title onDelete event on Chips mdChip - onDelete event on Chips Jun 9, 2015
@tagazok tagazok changed the title mdChip - onDelete event on Chips mdChip : onDelete event on Chips Jun 9, 2015
@daleknauss
Copy link

This would be awesome. In the mean time you can just do this:
<md-chips> <button class="md-chip-remove" ng-click="tagsCtrl.tagDeleted()" md-chip-remove> <md-icon md-svg-icon="md-close"></md-icon> </button> </md-chips>

@tomacf
Copy link

tomacf commented Jun 10, 2015

If you need to get the chip to remove in your ng-click function, just use $chip as parameter

@tagazok
Copy link
Author

tagazok commented Jun 10, 2015

Nice it works ! Thanks :)

@davthu
Copy link

davthu commented Jun 15, 2015

Thats all nice and good. However, the Delete key will still delete chips and the click handler will not be executed. I had to use a watch on the chips collection to deal with it properly.

@smashercosmo
Copy link

Yes, for now the only way to invoke a callback on chips change is to watch length of chips's ngModel ((

@ghost
Copy link

ghost commented Aug 3, 2015

@davthu can you post the solution to deal with the delete key ? i wnat to make only one of the chips unable to be deleted.

@davthu
Copy link

davthu commented Aug 4, 2015

This is basicly what we do. Watching the chips collection for changes in size and then finding the the diff (the removeChip function is not included here for simplicity):

$scope.$watchCollection('chips', function(newVal, oldVal) {
  // A chip has been removed if oldVal is greater in size than newVal
  if (angular.isArray(oldVal) && oldVal.length > newVal.length) {
    // Find the item(s) in oldVal that does
    // not exist anymore in newVal.
    var diff = oldVal.filter(function(a) {
      return newVal.filter(function(b) {
        return a === b;
      }).length == 0
    });

    if (diff.length == 1) {
     removeChip(diff[0]);
    }
  }
});

topherfangio added a commit that referenced this issue Aug 11, 2015
Users have requsted a way to be notified when a chip is removed
from the list.

closes #3190
@topherfangio topherfangio added the pr: merge ready This PR is ready for a caretaker to review label Aug 11, 2015
topherfangio added a commit that referenced this issue Aug 13, 2015
Users have requsted a way to be notified when a chip is removed
from the list.

closes #3190
kennethcachia pushed a commit to kennethcachia/material that referenced this issue Sep 23, 2015
Users have requsted a way to be notified when a chip is removed
from the list.

closes angular#3190
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
pr: merge ready This PR is ready for a caretaker to review
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants