Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select from angular2-material does not work when loading data from an observable #443

Closed
alissonb13 opened this issue Jan 18, 2019 · 0 comments

Comments

@alissonb13
Copy link

alissonb13 commented Jan 18, 2019

I'm having trouble trying to load the options of a select with data from an observable.

My component code:

declare var $: any;

@Component({
  selector: 'app-home-page-eventos',
  templateUrl: './home-page-eventos.component.html',
  styleUrls: ['./home-page-eventos.component.css']
})
export class HomePageEventosComponent implements OnInit {
  ngOnInit() {
    $(document).ready(function() {
      $('select').material_select();
    });
  }
}

My HTML template looks like this:

<div class="col l2 m2 s6 input-field">
  <select class="home-page-select home-page-eventos-select" materialize="material_select">
    <option value="" disabled selected>Estado</option>
    <option value="">São Paulo</option>
    <option value="">Rio de Janeiro</option>
    <option [value]="state.name" 
            *ngFor="let state of (responseStates$ | async)">
       {{state.name}}
    </option>
  </select>
</div>

The observable $ responseStates retrieves the data as expected, and if I inspect the HTML generated in the browser I can see a completely filled select with the data I expect. But this data is not loaded in the select dropdown on the screen.

I've read that the material_select () function has been deprecated and should now use the formSelect () function. However, when I do this substitution I get error messages in the console stating that the formSelect function can not be found in the file materialize.js, and in fact when I go to the file I can only find the material_select () function.

I'm using version 15.1.10 of the angular2-materialize package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant