I have 2 components: HomeComponent and UserComponent.
home.component.ts :
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {
constructor(private router: Router) { }
users = ['User1', 'User2', 'User3']
selectedVal = ''
ngOnInit() {
}
onChange(newValue) {
this.selectedVal = newValue
}
}
home.component.html :
<select class="custom-select custom-select-lg mb-3 content" [(ngModel)]="selectedVal" (ngModelChange)="onChange($event)" >
<option [value]="i" *ngFor="let i of users"> {{i}} </option>
</select>
<h1> Selected value is : {{selectedVal}} </h1>
When a value is selected in the list, I want to send the variable selectedVal from HomeComponent to UserComponent.
I'm trying to learn Angular, how can I do this ?