Essentially, when setting up authentication, it is important to include a flag that indicates whether a user is logged in or not. In this example, a boolean is used for this purpose. If the boolean is false, input is disabled. If the boolean is true (meaning the user is logged in), then the input is no longer disabled. This flag may need to be passed as a service if your authentication system is a separate component.
import {Component, NgModule, ViewChild} from '@angular/core'
import {BrowserModule} from '@angular/platform-browser'
@Component({
selector: 'my-app',
template: `
<div>
<h2>Hello {{name}}</h2>
<h2>login is "password"</h2>
<input [value]="password" (input)="password = $event.target.value"> <button (click)="Authed()">login</button>
<h2>search</h2>
<input [disabled]="!Auth">
</div>
`,
})
export class App {
name:string;
Auth: boolean;
password = "";
constructor() {
this.name = 'Angular2';
this.password = '';
}
onKey(event:any) { // without type info
this.password += event.target.password;
console.log(this.password);
}
Authed(){
if(this.password === "password"){
this.Auth = true;
}
else{
this.Auth = false;
}
}
}
To see a working example of the above concept, check out this Plunker link.