I have an Angular2 form template of component like this:
<div class="container">
<div class="input-group">
<label> Masukkan nik </label>
<input type="text" class="form-control" placeholder="Username" aria-describedby="basic-addon1" #name>
</div>
<button (click)="verifyNik(name.value)">Verify</button>
</div> <!-- /container -->
What I want to do if I click the Verify button is to get the value of name input and pass it to my function in my component, which is like this below:
verifyNik(nik){
if(this.idparam==nik.substring(1,4)){
console.log("true");
}
}
So, if the value of input name in template (and substring it) is equal to my id.param (which I get from subscribe id in Angular route), then the console log will be true; but the problem is that nothing comes out. How can I fix this?
My code to get my id.param is this:
private idchild:any;
f: FormGroup;
private idparam:any;
constructor(
private fb: FormBuilder,
private servicedev:DevService,
private complaintservice:ComplaintService,
private router: ActivatedRoute
) { }
ngOnInit() {
this.idchild = this.router.params.subscribe(params => {
let id = params['id'];
this.idparam=id;
// Retrieve Pet with Id route param
});
FormControlin HTML?