数字输入的最大/最小值不会触发md-error

时间:2017-07-17 14:29:41

标签: angular angular-material2

md-error未在我的输入中触发min / max。它虽然适用于“必需”。

我在app.module.ts中的NgModule中导入了MaterialModule。

HTML

  public amountFormControl = new FormControl('', [Validators.min(40), Validators.required, Validators.max(300)]);

ts档案

<div>
    <h4>Lift</h4>
    <hr />
        <dl class="dl-horizontal" id="details">
            <dt>
                @Html.DisplayNameFor(model => model.Id)
            </dt>

            <dd>
                @Html.DisplayFor(model => model.Id)
            </dd>

            <dt>
                @Html.DisplayNameFor(model => model.StartPoint)
            </dt>

            <dd id="startPoint">
                @Html.DisplayFor(model => model.StartPoint)
            </dd>

            <dt>
                @Html.DisplayNameFor(model => model.EndPoint)
            </dt>

            <dd id="endPoint">
                @Html.DisplayFor(model => model.EndPoint)
            </dd>

            <dt>
                @Html.DisplayNameFor(model => model.LiftDate)
            </dt>

            <dd>
                @Html.DisplayFor(model => model.LiftDate)
            </dd>

            <dt>
                @Html.DisplayNameFor(model => model.OutboundStartTime)
            </dt>

            <dd>
                @Html.DisplayFor(model => model.OutboundStartTime)
            </dd>

            <dt>
                @Html.DisplayNameFor(model => model.OutboundEndTime)
            </dt>

            <dd>
                @Html.DisplayFor(model => model.OutboundEndTime)
            </dd>

            <dt>
                @Html.DisplayNameFor(model => model.InboundStartTime)
            </dt>

            <dd>
                @Html.DisplayFor(model => model.InboundStartTime)
            </dd>

            <dt>
                @Html.DisplayNameFor(model => model.InboundEndTime)
            </dt>

            <dd>
                @Html.DisplayFor(model => model.InboundEndTime)
            </dd>

            <dt>
                @Html.DisplayNameFor(model => model.UserEmailAddress)
            </dt>

            <dd>
                @Html.DisplayFor(model => model.UserEmailAddress)
            </dd>

            <dt>
                @Html.DisplayNameFor(model => model.UserId)
            </dt>

            <dd>
                @Html.DisplayFor(model => model.UserId)
            </dd>
        </dl>
    </div>
    <div id="LiftRequest-dialog" title="Request Lift">
        @Html.Action("RequestLiftPartialView", new Carpool.Models.RequestLift())
    </div>

1 个答案:

答案 0 :(得分:0)

尝试使用minlengthmaxlength代替minmax

那是Angular docs中的文件。

  

Angular表单包含许多内置验证器函数,这些函数可帮助您检查表单中的常见用户输入。除了minlengthmaxlengthrequired此处介绍的内置验证器之外,还有其他诸如emailpattern的反应表单。