InfomediaLtd / angular2-materialize

Angular 2 support for Materialize CSS framework.
https://infomedialtd.github.io/angular2-materialize/
MIT License
407 stars 140 forks source link

Autocomplete and NgModel #79

Open ziracmo opened 8 years ago

ziracmo commented 8 years ago

The autocompletion from materialize doesn't trigger the ngModel when you click on it. The ngModel is using the string we wrote and not the one we clicked on in the autocompletion.

I'm wondering if it's a error comming from materialize or angular 2.

rubyboy commented 8 years ago

Would you be able to provide example code that reproduces that? Thanks.

maxmumford commented 8 years ago

I'm also experiencing this issue with the following code:

<input type="text" [(ngModel)]="createThreadLocation" name="createThreadLocation" 
          id="createThreadLocation" materialize="autocomplete" [materializeParams]="[{'data': {'apple': null, 'google': null}}]">

With the following versions:

    "angular2-materialize": "^5.1.0",
    "materialize-css": "^0.97.7"

Ie if the user types in "a", clicks "apple" in the drop down list, then the createThreadLocation property is still set to "a".

arlowhite commented 8 years ago

I've been struggling with this as well.

jQuery events don't trigger Angular2's events. See: http://stackoverflow.com/questions/38557175/angular2-and-jquery-change-events

Just hooking the jQuery event as in acdcjunior's answer seems best.

Also, I noticed that there's actually a bug related to this in materialize-css 0.97.7, trigger('change') is missing. This has been fixed in master:

https://github.com/Dogfalo/materialize/blob/master/js/forms.js#L353 $input.trigger('change');

Until the next materialize-css release, you'll have to get materialize-css from GitHub and build it manually.

package.json "materialize-css": "Dogfalo/materialize#47b2f3f8c4b149d4330d554415bc798b889331c8",

cd node_modules/materialize-css npm install grunt release

ekirin commented 7 years ago

I didn't understand how to workaround. Suggest, please.