0
I’m having a problem where the angular is not assigning value to the variable of an input field of mine.
Follows the code:
Component.html
<div class="row justify-content-center" id="formulario">
<form class="form-inline" (submit)="findRegister(nameInput.value)">
<input #nameInput type="text" class="form-control mb-2 mr-sm-2 mb-sm-0" placeholder="Jane Doe">
<button type="submit" class="btn btn-primary">Pesquisar</button>
</form>
</div>
Component.
import { Component, OnInit } from '@angular/core';
import { DataService } from '../services/data.service';
@Component({
selector: 'app-table',
templateUrl: './table.component.html',
styleUrls: ['./table.component.css']
})
export class TableComponent implements OnInit {
offset:number;
registers:Register[];
constructor(private dataService:DataService) { }
findRegister(value){
this.dataService.getRegisters(value, this.offset).subscribe(registers => {
this.registers = registers.data;
console.log(this.registers);
}, err => {
console.log(err);
});
}
ngOnInit() {
this.offset=1;
this.findRegister("Luiz");
}
incrementOffset(){
this.offset++;
this.findRegister("luiz");
}
decrementOffset(){
this.offset--;
this.findRegister("luiz");
}
}
interface Register{
id: string,
name: string,
username: string;
}
I made some calls to findRegister passing a string just to test the service, which is working all ok.
I had already done it but I did not obtain result.
– Fabiano Amaral
Although you are using a form the wrong way as it is recommended. Later arriving home I put the code in the ideal way for you to use.
– Giovane
@Fabianoamaral made some tests here with his code using (Ubmit) and (ngSubmit) and both are working normally. You are importing Formsmodule into your component module?
– Giovane
It was the Formsmodule!
– Fabiano Amaral