本文整理汇总了TypeScript中@angular/forms.AbstractControl.get方法的典型用法代码示例。如果您正苦于以下问题:TypeScript AbstractControl.get方法的具体用法?TypeScript AbstractControl.get怎么用?TypeScript AbstractControl.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@angular/forms.AbstractControl
的用法示例。
在下文中一共展示了AbstractControl.get方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: dateRangeValidator
export function dateRangeValidator(c: AbstractControl): {[key: string]: any} {
// Get controls in group
const startDateC = c.get('startDate');
const startTimeC = c.get('startTime');
const endDateC = c.get('endDate');
const endTimeC = c.get('endTime');
// Object to return if date is invalid
const invalidObj = { 'dateRange': true };
// If start and end dates are valid, can check range (with prefilled times)
// Final check happens when all dates/times are valid
if (startDateC.valid && endDateC.valid) {
const checkStartTime = startTimeC.invalid ? '12:00 AM' : startTimeC.value;
const checkEndTime = endTimeC.invalid ? '11:59 PM' : endTimeC.value;
const startDatetime = stringsToDate(startDateC.value, checkStartTime);
const endDatetime = stringsToDate(endDateC.value, checkEndTime);
if (endDatetime >= startDatetime) {
return null;
} else {
return invalidObj;
}
}
return null;
}
示例2:
export const passwordMatcher = (control: AbstractControl): {[key: string]: boolean} => {
const password = control.get('password');
const confirm = control.get('confirm');
if (!password || !confirm) {
return null;
}
return password.value === confirm.value ? null : { nomatch: true };
};
示例3: PasswordValidator
export function PasswordValidator(control: AbstractControl): { [key: string]: boolean } | null {
const password = control.get('password');
const confirmPassword = control.get('confirmPassword');
if (password.pristine || confirmPassword.pristine) {
return null;
}
return password && confirmPassword && password.value !== confirmPassword.value ? { 'misMatch': true } : null;
}
示例4: passwordsShouldMatch
static passwordsShouldMatch(control: AbstractControl) {
let newPassword = control.get('newPassword');
let confirmPassword = control.get('confirmPassword');
if (newPassword.value !== confirmPassword.value)
return { passwordsShouldMatch: true };
return null;
}
示例5: MatchPassword
static MatchPassword(AC: AbstractControl) {
const newPassword = AC.get('newPassword').value; // to get value in input tag
const newPassword2 = AC.get('newPassword2').value; // to get value in input tag
if (newPassword !== newPassword2) {
AC.get('newPassword2').setErrors( {MatchPassword: true} );
} else {
return null;
}
}
示例6: MatchPassword
static MatchPassword(AC: AbstractControl): any {
let password = AC.get('password').value; // Get the password input value
let passwordConfirm = AC.get('passwordConfirm').value; // get the passwordConfirm input value
if(password != passwordConfirm) {
AC.get('passwordConfirm').setErrors( {MatchPassword: true} )
} else {
return null
}
}
示例7: comparePasswords
comparePasswords(c: AbstractControl): { [key: string]: boolean } {
const pass = c.get('password');
const repeatPassword = c.get('repeatPassword');
if (pass.value !== repeatPassword.value) {
return { 'match': true };
}
return null;
}
示例8: ConfirmPasswordValidator
static ConfirmPasswordValidator(control: AbstractControl) {
const value = control.get('password').value;
const otherValue = control.get('confirmpassword').value;
if (value !== otherValue) {
control.get('confirmpassword').setErrors({MatchError: true});
} else {
return null;
}
};
示例9: return
return (control: AbstractControl): {[key: string]: any} | null => {
const password = control.get('newpassword').value;
const confirmPassword = control.get('confirmpassword').value;
const isValid = password === confirmPassword;
if (!isValid) {
control.get('confirmpassword').setErrors({matchPassword: true});
}
return isValid ? null : {'matchPassword': {value: confirmPassword}};
};
示例10: MatchPassword
static MatchPassword(AC: AbstractControl) {
const password = AC.get('password').value; // to get value in input tag
const confirmPassword = AC.get('confirmPassword').value; // to get value in input tag
if (password !== confirmPassword) {
AC.get('confirmPassword').setErrors({ MatchPassword: true });
} else {
return null;
}
}