假设存在一个表单,并且有两个按钮,我希望一个按钮被禁用,直到用户填满所有参数,而其他参数为“ Enabled”,供用户导航到后面板。是否存在一个为按钮分配唯一ID的功能?
Edit1: Tried to disable one of the button,until all the text-form field in the page is touched by users,once user enters all the required parameters ,then the button gets enabled!
答案 0 :(得分:1)
您不需要唯一的ID
export class AuthenticationService {
private currentUserSubject: BehaviorSubject < User > ;
public currentUser: Observable < User > ;
private baseUrl: string = environment.apiUrl;
constructor(private http: HttpClient) {
this.currentUserSubject = new BehaviorSubject < User > (JSON.parse(localStorage.getItem('currentUser')));
this.currentUser = this.currentUserSubject.asObservable();
}
public get currentUserValue(): User {
return this.currentUserSubject.value;
}
login(User) {
console.log("User values check" + User)
const headers = new HttpHeaders({
'Content-Type', 'application/x-www-form-urlencoded'
});
return this.http.post < any > (this.baseUrl + 'api/authenticate/', User, {
headers,
responseType: "json",
observe: 'response'
})
.pipe(map((user => {
// login successful if there's a jwt token in the response
console.log("user values" + user.headers.get('Token'))
if (user && user.headers.get('Token')) {
console.log("Reached tokens!!!")
// store user details and jwt token in local storage to keep user logged in between page refreshes
localStorage.setItem('currentUser', JSON.stringify(user));
this.currentUserSubject.next(user);
}
/* this.http.put(apiURL, JSON.stringify(json),
{observe:'response'}).subscribe((res:Response) =>
console.log(res));*/
return user;
})));
}
logout() {
// remove user from local storage to log user out
localStorage.removeItem('currentUser');
this.currentUserSubject.next(null);
}
}