Min and max value of input in angular4 application

后端 未结 9 1114
温柔的废话
温柔的废话 2020-12-08 13:01

I have an angular4 application with a form. In this one I have an input to enter a percentage. So, I want to block the input with value between 0 and 100. I tried to add

9条回答
  •  隐瞒了意图╮
    2020-12-08 13:55

    I succeeded by using a form control. This is my html code :

        
            
            Please enter a value between 0 and 100
        
    

    And in my typescript code, I have :

            this.rateControl = new FormControl("", [Validators.max(100), Validators.min(0)])
    

    So, if we enter a value higher than 100 or smaller than 0, the material design input become red and the field is not validate. So after, if the value is not good, I don't save when I click on the save button.

提交回复
热议问题