material icon indicating copy to clipboard operation
material copied to clipboard

feat(contact-chips): add support for md-on-add/remove/select

Open recursionbane opened this issue 8 years ago • 11 comments

Actual Behavior:

  • What is the issue? * md-contact-chips do not appear to support md-on-add/remove/select bindings
  • What is the expected behavior? md-contact-chips should inherit functionality from md-chips, which do support these bindigs

CodePen (or steps to reproduce the issue): *

  • CodePen Demo which shows your issue: http://codepen.io/recursionbane/pen/dOWWOV
  • Details: Adding, removing or selecting a chip should send messages to console.log(), but nothing happens

Angular Versions: *

  • Angular Version: https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.js
  • Angular Material Version: https://cdn.gitcdn.link/cdn/angular/bower-material/v1.1.1/angular-material.js

Additional Information:

  • Browser Type: * Chrome
  • Browser Version: * 54.0.2840.99 m (64-bit)
  • OS: * Windows 7 Enterprise
  • Stack Traces: None

UPDATE: md-removable doesn't work, either!

recursionbane avatar Nov 22 '16 23:11 recursionbane

Up, still not working

skapin avatar Dec 23 '16 16:12 skapin

For the one who want to patch it:

Add :

md-on-add="$mdContactChipsCtrl.mdOnAdd()($chip)"\
md-on-remove="$mdContactChipsCtrl.onRemove()($chip)"\

to MD_CONTACT_CHIPS_TEMPLATE in angular-material

(like this)

var MD_CONTACT_CHIPS_TEMPLATE = '\
      <md-chips class="md-contact-chips"\
          ng-model="$mdContactChipsCtrl.contacts"\
          md-require-match="$mdContactChipsCtrl.requireMatch"\
          md-on-add="$mdContactChipsCtrl.mdOnAdd()($chip)"\
          md-on-remove="$mdContactChipsCtrl.onRemove()($chip)"\
          md-autocomplete-snap>\
          <md-autocomplete\

skapin avatar Dec 23 '16 17:12 skapin

@skapin You interested in submitting a PR? This seems like a since/simple/safe addition :-)

topherfangio avatar Jan 10 '17 18:01 topherfangio

I can yes, but i need to overcheck it again, (especially if no func. is specified)

skapin avatar Jan 11 '17 14:01 skapin

Hello! Can we get a solution of this problem?

daniymilner avatar Apr 02 '17 17:04 daniymilner

An answer is above, check my previous post :)

skapin avatar Apr 03 '17 06:04 skapin

For the glory of satan, I repost updated for easy use :

var MD_CONTACT_CHIPS_TEMPLATE = '\
      <md-chips class="md-contact-chips"\
          ng-model="$ContactChipsCtrl.contacts"\
          md-require-match="$ContactChipsCtrl.requireMatch"\
          md-max-chips="{{$ContactChipsCtrl.maxChips}}"\
          md-on-add="$ContactChipsCtrl.mdOnAdd()($chip)"\
          md-on-remove="$ContactChipsCtrl.mdOnRemove()($chip)"\
          md-autocomplete-snap>\

AND then in the Ctrl :

return {
    template: function(element, attrs) {
      return MD_CONTACT_CHIPS_TEMPLATE;
    },
    restrict: 'E',
    controller: 'ContactChipsCtrl',
    controllerAs: '$ContactChipsCtrl',
    bindToController: true,
    compile: compile,
    scope: {
      contactQuery: '&mdContacts',
      placeholder: '@',
      secondaryPlaceholder: '@',
      contactName: '@mdContactName',
      contactImage: '@mdContactImage',
      contactEmail: '@mdContactEmail',
      mdOnAdd: '&',    /** This is new **/
      mdOnRemove: '&',  /** This is new **/
      contacts: '=ngModel',
      maxChips: '@?mdMaxChips',
      requireMatch: '=?mdRequireMatch',
      highlightFlags: '@?mdHighlightFlags'
    }
  };

Feel free to update and share. I use this code in a redefined ctrl to avoid colision with existing one. I changed some name to post it here as much generic as possible.

skapin avatar Apr 03 '17 06:04 skapin

I'd like to upvote this fix. Do we just need a PR put together? I blew 4+ hour on this issue today assuming that md-contact-chips conformed to the same interface as md-chips (because I didn't know there was a difference.) Especially since on the documentation md-chips and md-contact-chips are presented on the same demo page: https://material.angularjs.org/latest/demo/chips

This is all coming from a newby to this project.

edgartheunready avatar Jun 26 '17 19:06 edgartheunready

In my opinion, switching to angular material >= 1.1.2 fixes this issue. Maybe I don't completely understand but I think this is resolved.

batsauto avatar Aug 04 '17 16:08 batsauto

I can confirm the issue still persists with v1.1.5; would be great if it would be fixed. md-contact-chips should have the same functionality than md-chips

tux1337 avatar Dec 29 '17 19:12 tux1337

Yes, please put a PR together from the above and we'll try to get it merged.

Splaktar avatar Mar 04 '18 02:03 Splaktar