angularjs - 验证错误消息

时间:2017-06-07 06:14:34

标签: jquery angularjs

有人可以解释下面的代码吗,我是棱角分明的新人请帮助我:

{% if validation_error %}
   <div>{{ validation_error }}</div>
{% endif %}  

在网页上:

enter image description here

完整代码:

<form name="login" method="POST" action="/app/login">
    <div class="form-container">
        <fieldset class="form-group">
            <input class="form-control form-control-sm text-uppercase" id="username" name="username" type="text" placeholder="Username">
            <input class="form-control form-control-sm" name="password" type="password" placeholder="Password">
        </fieldset>
        <button class="btn btn-primary btn-sm btn-block">signin</button>
        {% if validation_error %}
            <div class="small text-danger m-t-1">{{ validation_error }}</div>
        {% endif %}
    </div>
</form>

4 个答案:

答案 0 :(得分:0)

ng-show标记添加到div

<div ng-show="login.username.$invalid && !login.username.$pristine" class="small text-danger m-t-1">You name is required.</div>

答案 1 :(得分:0)

您可以使用带有表单的角度验证和输入&#39;名称;

<form name="login" method="POST" action="/app/login">
    <div class="form-container">
        <fieldset class="form-group">
            <input class="form-control form-control-sm text-uppercase" id="username" name="username" type="text" placeholder="Username">
            <input class="form-control form-control-sm" name="password" type="password" placeholder="Password">
        </fieldset>
        <button class="btn btn-primary btn-sm btn-block" ng-disabled="!login.$valid">signin</button>

        <div ng-if="!login.$valid" class="small text-danger m-t-1">form not valid</div>
        <div ng-if="!login.username.$valid" class="small text-danger m-t-1">username not valid</div>
    </div>
</form>

更多信息:https://www.w3schools.com/angular/angular_validation.asp

答案 2 :(得分:0)

我不确定,但这可能是使用twig的模板语法。

例如

{% if online == false %}
    <p>no one is online.</p>
{% endif %}

答案 3 :(得分:0)

这是twig模板语法。

示例:

<!DOCTYPE html>
<html>
    <head>
        <title>My Webpage</title>
    </head>
    <body>
        <ul id="navigation">
        {% for item in navigation %}
            <li><a href="{{ item.href }}">{{ item.caption }}</a></li>
        {% endfor %}
        </ul>

        <h1>My Webpage</h1>
        {{ a_variable }}
    </body>
</html>