krescruz / angular-materialize

Angularjs directives for Materialize CSS Framework https://github.com/Dogfalo/materialize
MIT License
397 stars 129 forks source link

Chips changes model structure #222

Open svickers opened 7 years ago

svickers commented 7 years ago

When using chips the structure of the model changes when an item is added or deleted.

The materialize chips component expects an array with a tag property like so: [{tag:'chip1'},{tag:'chip2'}]

The initial binding works just fine but as soon as you add a new chip, angular.materialize.chips actually changes your model to: ['chip1','chip2']

This is the offending line: https://github.com/krescruz/angular-materialize/commit/ad6a7fbc28431de9d0ee1a524c7532d18eab7fa4#diff-002acb22231043b6342eac8068420c4cR145

scope.ngModel =element.data().chips.map(function (item) { return item.tag })

I think it should just be:

scope.ngModel = element.data().chips;

Example: http://jsfiddle.net/gmse4pgc/6/