question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to bind NgModel to Select with static options

See original GitHub issue

We have tried multiple ways of doing this, but it doesnt seem to be working. Whenever we try to bind a select with ngModel the (already populated) initial value never gets set. On the example project it does… I cant tell what is different, I know there is a thrid part issue with the modal options (materializecss causing that) but with this I am at a loss… this is an absolute must have, and its not working as intended, is there some sort of configuration i am missing?

<mz-select-container class="col s6">
  <select mz-select
    id="options-select"
    [label]="'Label'"
    [placeholder]="'Select a Title'"
    [(ngModel)]="editTherapist.title">
    <option [ngValue]=1>BCBA</option>
    <option [ngValue]=2>RBT</option>
  </select>
</mz-select-container>

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
detchisoncommented, Jul 31, 2017

Doesn’t work either way, we have moved onto using Reactive forms and setting the values that way

1reaction
jfcerecommented, Aug 1, 2017

Hi @detchison,

Thanks for reporting the issue. With your code sample I’ve been able to reproduce the problem. The demo application example that works with ngModel uses ngFor on options. If I use it on your example it works great.

We are going to fix it with static options but in the meanwhile you could use it that way…

example.component.html
<mz-select-container class="col s6">
  <select mz-select
    id="options-select"
    [label]="'Label'"
    [placeholder]="'Select a Title'"
    [(ngModel)]="editTherapist.title">
    <option *ngFor="let title of titles" [value]="title.value">{{ title.text }}</option>
  </select>
</mz-select-container>
example.component.ts
titles = [
  { value: 1, text: 'BCBA' },
  { value: 2, text: 'RBT' },
];

editTherapist = {
  title: 1,
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular error: "Can't bind to 'ngModel' since it isn't a known ...
In order to use two-way data binding for form inputs you need to import the FormsModule package in your Angular module.
Read more >
Angular Select List Value not binding with Static Values
In Angular 1.3 I was simply able to bind these static values using ng-model like this: <select class="form-control-small" ng-model="view.
Read more >
can't bind to 'items' since it isn't a known property of 'ng-select'
Uncaught Error: Template parse errors: Can't bind to 'ngModel' since it isn't a known property of 'ng-select'. 1. If 'ngModel' is an Angular...
Read more >
Can't bind to 'ngModel' since it isn't a known property of 'input'
I'm getting this error even though I imported the FormsModule. Here is my html login form.
Read more >
NgModule FAQ - Angular
What does "Can't bind to 'x' since it isn't a known property of 'y'" mean?link ... An NgModule can export a combination of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found