I'm working with an input field with type="number"
and I specifically want to use ng-min="0"
. I'm unsure what I'm doing wrong, but I don't see any message when I enter a value below zero into my field with my current implementation.
I did make sure to include angular messages like so: angular.module('myApp', ['ngMessages'])
.
My code:
<admin-form name="formName">
<admin-field>
<input
name="formName"
ng-model="$ctrl.model.whatever"
type="number"
min="0" />
<div ng-messages="userForm.formName.$error" style="color: maroon" role="alert">
<ng-message when="min">Value cannot be below 0</ng-message>
</div>
A working plunkr is available here: https://plnkr.co/edit/PUT7r1hNbJrjHDF0vhJd
The PLNKR used obsolete libraries. With updated libraries, it works:
angular.module('myapp', ['ngMessages'])
<script src="//unpkg.com/angular/angular.js"></script> <script src="//unpkg.com/angular-messages/angular-messages.js"></script> <body ng-app="myapp"> <form name="myForm"> <label>Enter your number:</label><br> <input type="number" name="myNumber" ng-model="num" ng-min="0" role="alert"> <div ng-messages="myForm.myNumber.$error" style="color:red"> <div ng-message="min">Your field value is lesser minimum value</div> </div> </form> </body>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.