【发布时间】:2017-01-27 03:54:42
【问题描述】:
我想只在创建过程中对用户表单进行验证,而不是更新
这是我的验证逻辑
this.userform = this._formbuilder.group({
first_name: ['', Validators.required],
last_name: ['', Validators.required],
username: ['', Validators.compose(
[
Validators.required,Validators.minLength(5)
]
)],
password: ['',Validators.compose([
Validators.required,ValidationService.passwordValidator
])],
email: ['', Validators.compose([
Validators.required,ValidationService.emailValidator
])],
role: ['', Validators.required],
})
我想仅在创建期间验证密码,也就是 newuser 变量为真时,所以我尝试过
this.userform = this._formbuilder.group({
.....
password: ['',
(this.newUser) ?Validators.compose([
Validators.required,ValidationService.passwordValidator
]):""
],
....
})
上述失败并返回错误
rror: Error in ./UsersComponent class UsersComponent - inline
template:113:51 caused by:
v is not a function
Error: Error in ./UsersComponent class UsersComponent -
inline template:113:51 caused by: v is not a function
【问题讨论】:
-
this.newUser 设置在哪里?
-
尝试通过
null而不是"":this.newUser ? Validators.compose(...) : null
标签: angular typescript