I've created a text input like below:
<input
id="tenancyName"
#tenancyName="ngModel"
class="register__form__control"
autoFocus
type="text"
placeholder="Business Name"
[(ngModel)]="model.tenancyName"
name="tenancyName"
required
maxlength="64" />
and after my input, I have a div which is a warning that the business name they have entered is already taken.
<div [class.taken]="taken === true" class="register__warning">
<p>Sorry, Business Name is already taken</p>
</div>
then in my component.ts
import ... from ...
import * as _ from 'lodash';
@component...
export class...
taken: boolean;
ngOnInt() {
const businessInput = <HTMLInputElement>document.getElementById('tenancyName');
businessInput.addEventListener('keyup', _.debounce(this.checkTenantName, 1000));
}
checkTenantName() {
this.taken = true;
}
so basically, what is happening is that I'm using the debounce
function from lodash
to call a function after the user has stopped typing for 1s now the function does fire but the register__warning
doesn't get the .taken
class
Im not sure what im doing wrong.. any help would be appreciated
EDIT
I have put a console.log() in the checkTenantName() function like so
checkTenantName() {
this.taken = true;
console.log(this.taken);
}
and I get true returned in console.. so Im not sure why my div wouldn't be getting the .taken
class
Thanks