我正在对表单中的两个字段实施跨字段验证(基于反应/模型的方法),并且不知道应该如何将错误添加到表单控件的现有错误列表中
形式:
this.myForm = new FormGroup({
name: new FormControl('', Validators.minLength(3));
city: new FormGroup({
cityOne: new FormControl('', Validators.minLength(3)),
cityTwo: new FormControl('', Validators.minLength(3))
}, this.validateEqualCities)
});
Run Code Online (Sandbox Code Playgroud)
验证器:
validateEqualCities(formGroup: FormGroup) {
return (control: AbstractControl): { [key: string]: any } => {
if (formGroup.controls['cityOne'].value && formGroup.controls['cityTwo'].value && formGroup.controls['cityOne'].value !== formGroup.controls['cityTwo'].value) {
formGroup.controls['cityOne'].setErrors({ 'equalCities': true }, { emitEvent: true });
formGroup.controls['cityTwo'].setErrors({ 'equalCities': true }, { emitEvent: true });
return { 'equalCities': false };
} else {
formGroup.controls['cityOne'].updateValueAndValidity({ onlySelf: true, emitEvent: false });
formGroup.controls['cityTwo'].updateValueAndValidity({ onlySelf: true, …
Run Code Online (Sandbox Code Playgroud) 我是春季和春季靴子的新手,所以希望这不是一个愚蠢的问题.
我有几个实现的接口.实现注释为@Component("NameOfImpl")
.
我的目标是使用选定的实现自动装配bean.在正常情况下我可以使用@Autowired @Qualifier("NameOfImpl")
,但我的问题是我想在一个方法中选择一个实现,如:
public void doSomethingMethod(){
for(String line: configFile){
String[] values = line.split(";");
if (values[0].equals("A")) {
//here I want to select an bean implementation
}
else if (values[0].equals("B")) {
//here I want to select another bean implementation
}
}
bean.doSomething();
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?你有什么建议?谢谢!
我的应用程序中有一个后退按钮,可以向后导航一些级别。如果是一级
this.router.navigate(['..'], { relativeTo: this.route });
Run Code Online (Sandbox Code Playgroud)
效果很好(生成的路由网址:)http://localhost:3000/three/two/one
。在两级后退的情况下。导航
this.router.navigate(['..', '..'], { relativeTo: this.route });
Run Code Online (Sandbox Code Playgroud)
路由器向后导航两个级别,但生成的路由网址现在看起来像http://localhost:3000/three/two/
(尾部斜杠,这是不正确的)。
我是在做错什么还是可能是错误?
angular ×2
autowired ×1
form-control ×1
forms ×1
freemarker ×1
java ×1
keycloak ×1
navigation ×1
routing ×1
spring ×1
spring-boot ×1
spring-mvc ×1
validation ×1