2017-06-07 55 views
0

有人可以解釋我下面的代碼,我是新來的角請幫助我: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> 
+0

你需要的JS,以及瞭解它。它會檢查是否存在驗證錯誤(如果角色'validation_error'中的變量)爲true,然後顯示告訴你驗證錯誤是什麼的div。 – marcellothearcane

+0

看起來像它可能是[django角](http://django-angular.readthedocs.io/en/latest/) – marcellothearcane

+0

@marcellothearcane什麼是參考js文件使用這種代碼 – rb4bhushan

回答

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> 
0

您可以使用窗體和輸入名稱進行角度驗證;

<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

0

我不知道,但是這可能是使用twig的模板語法。

例如,

{% if online == false %} 
    <p>no one is online.</p> 
{% endif %} 
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>