角度2分量允许输入值

时间:2018-03-30 12:22:06

标签: angular typescript angular2-components

我有一个组件,例如

export class Foo {
@Input() myInput:string = 'a';

}

现在我希望myInput的允许值仅为以下任意值:abcd

如果有人试图

<foo myInput="x">

他应该收到编译错误

我相信这是可能的

由于

1 个答案:

答案 0 :(得分:3)

您想要实现的目标可以通过

完成
router.get('/verify/:token', function(req,res){
  User.findOne({ verificationToken: req.params.token, resetPasswordExpires: { $gt: Date.now()}}, function(err, user){
      if(err){
          console.log(err);
          //here is where i wish to pass in the link for verification link//
          req.flash('error', 'Mail verify token is invalid or has expired' + resend link here + '.')
          return res.redirect('/forgot')
      } else {
          user.active = "true"
          user.save()
          console.log(user.active);
          req.flash('success', 'Your mail have been verified successfully')
          res.redirect('/login');
      }
  })
})

<% if(error && error.length > 0) { %>
    <div class="alert alert-danger alert-dismissible deposit-alert" role="alert">
        <div class="container">
            <%= error %>
        </div>
    </div>
<% } %>

通过执行此操作,您明确告诉export class Foo { @Input() myInput: ’a’ | ‘b’ | ‘c’ | ‘d’; } 仅允许绑定TypeScript的特定字符

您可以在documentation

中详细了解myInput警卫和type定义