Angular JS中未显示错误消息

时间:2018-01-02 12:15:28

标签: javascript html angularjs

我试图使用下面的代码显示一些登录验证错误,但它不起作用。
当我点击“登录”按钮时,它将转到下一页,错误消息不会显示为假设。
有什么想法吗?

index.html的: -

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
<script type="lib/angular.min.js"></script>
<script type="angularFile.js"></script>
</head>
<body ng-app="demoApp" ng-controller="Ctrl">
<h1>Login Form</h1>
<form action="next.html" ng-submit="fun1($event)">
userName:<input name="name" ng-model="un">
<div style="color: red">{{msg1}}</div><br>
passWord:<input type="password" name="pwd" ng-model="pw">
<div style="color: red">{{msg2}}</div><br>
<input type="submit" value="Login"/>
</body>
</html>

angularFile.js:

var app = angular.modul("demoApp",[]);

app.controller("Ctrl",function($scope){

    $scope.un="";
    $scope.pw="";
    $scope.msg1="";
    $scope.msg2="";
    $scope.fun1=function(e){

        if($scope.un.leggth==0){
            $scope.msg1="please enter user name"
                e.preventDefault();
        }else{
            $scope.msg1="";
        }

        if($scope.pw.leggth==0){
            $scope.msg2="please enter password"
                e.preventDefault();
        }else{
            $scope.msg2="";
        }
    }
});

3 个答案:

答案 0 :(得分:1)

xml.etree.ElementTree

Working plunker

使用此代码告诉我。

确保您已正确导入库或从Web

导入库
import xml.etree.ElementTree as ET

tree = ET.parse('data.xml')
root = tree.getroot()
for responses in root.findall('./B/C/F/F1'):
    date = responses.find('./F11/DATE-REPORTED').text
    print(a)

答案 1 :(得分:0)

您尚未在html中关闭表单标记。以及其他开发人员建议的所有其他事情。

 <div ng-app="demoApp" ng-controller="Ctrl">
    <h1>Login Form</h1>
    <form ng-submit="fun1($event)">
    userName:<input name="name" ng-model="un">
    <div style="color: red">{{msg1}}</div><br>
    passWord:<input type="password" name="pwd" ng-model="pw">
    <div style="color: red">{{msg2}}</div><br>
    <input type="submit" value="Login"/>
    </form>
    </div>

内部控制器 -

var app = angular.module("demoApp",[]);

app.controller("Ctrl",function($scope){

    $scope.un="";
    $scope.pw="";
    $scope.msg1="";
    $scope.msg2="";
    $scope.fun1=function(e){

        if($scope.un.length==0){
            $scope.msg1="please enter user name"
                e.preventDefault();
        }else{
            $scope.msg1="";
        }

        if($scope.pw.length==0){
            $scope.msg2="please enter password"
                e.preventDefault();
        }else{
            $scope.msg2="";
        }
    }
});

工作jsfiddle链接 - JSFIDDLE

答案 2 :(得分:0)

它是angular.module();

您已将其设为angular.modul()

var app = angular.module("demoApp", []);

同时将$scope.pw.leggth$scope.un.leggth中的拼写修复为length

你需要解决这些问题,它会起作用。