I have a dropdown with few values and based on the value selected, the input field value should be set.
Here is my html code
<nb-card>
<nb-card-header>
Services
</nb-card-header>
<nb-card-body>
<form>
<div class="row">
<div class="col-sm-4">
<div class="row">
<label for="bgrp" class="label col-sm-3 form-control-label">Services</label>
<div class="col-sm-9">
<nb-select selected="1" fullWidth id="service" (change)=onChange($event)>
<nb-option *ngFor="let service of Services" [value]="service">{{service.name}}</nb-option>
</nb-select>
</div>
</div>
</div>
<div class="col-sm-4">
<div class="row">
<label for="bgrp" class="label col-sm-3 form-control-label">Unit Price</label>
<div class="col-sm-9">
<input type="number" nbInput fullWidth id="name" name="price"/>
</div>
</div>
</div>
<div class="col-sm-4">
<div class="row">
<label for="bgrp" class="label col-sm-3 form-control-label">Discount</label>
<div class="col-sm-9">
<input type="number" nbInput fullWidth id="name" placeholder="Name"/>
</div>
</div>
</div>
</div>
</form>
</nb-card-body>
</nb-card>
And my typescript file is
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormBuilder, FormControl, Validators } from '@angular/forms'
@Component({
selector: 'ngx-service',
templateUrl: './service.component.html',
styleUrls: ['./service.component.scss']
})
export class ServiceComponent implements OnInit {
Services: any=[
{name: 'Consultation', price: 100},
{name: 'Follow Up', price: 200},
{name: '24 Hrs. Creatinine', price: 300},
{name: 'Complete Blood Count - CBC', price: 400},
{name: 'X-Ray', price: 500}];
ngOnInit() {
}
public onChange(event){
const val = event.target.value;
this.price.setValue(event.target.value,{
onlySelf: true
})
}
}
So if consultation is selected, price should be set to 100. if x ray is selected, price should be set to 500.
I want it using reactiveformmodule methods Help me out...