I try to make search form for movie database with dropdown datalist with search results, and when click to option I want to move to movie page. But I can't figure out how to hide [value] string in <option [value]>. Here is my code:
<form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2"
required
list="foundMovies"
[(ngModel)]="searchString"
[ngModelOptions]="{standalone: true}"
(ngModelChange)="startSearch($event)"
type="search" placeholder="Search" aria-label="Search">
<datalist id="foundMovies">
<option *ngFor="let movie of foundMovies"
[value]="movie.id"
> {{movie.title}} </option>
</datalist>
<button
(click)="submitForm()"
class="btn btn-outline-success my-2 my-sm-0" >Найти</button>
</form>
and here is ts file:
import { Component, OnInit } from '@angular/core';
import {MovieService} from '../../../model/movie.service';
import {Movie} from '../../../model/movie';
@Component({
selector: 'app-movie-search-form',
templateUrl: './movie-search-form.component.html',
styleUrls: ['./movie-search-form.component.css']
})
export class MovieSearchFormComponent implements OnInit {
searchString: Movie;
foundMovies: Movie[];
constructor(private movieService: MovieService) { }
ngOnInit(): void {
}
submitForm(): void{
console.log(this.searchString);
}
startSearch(search): void {
console.log(search);
if (search.length >= 3) {
this.movieService.searchForMovies(search)
.subscribe(result => {
if (result.length){
this.foundMovies = result;
}
});
}
}
}
the main problen that when I use [ngValue] with options I can't get movie.id in startSearch(search): void {
console.log(search); string, I allways get the name of the movie, and if I use [value] instead I get movie.id when choose option, but I can't hide movie.id on dropdown list of options.
So the question is how to hide movie.id, when I use [value] with options, or how can I use [ngValue] such way, to get movie.id when I select some option.
Using [ngValue]
![Using [ngValue]](https://gamingcommission.club/i.sstatic.net/VBkcB.png)
