角表单验证NG-禁用不工作 [英] Angular form validation ng-disabled not working
问题描述
我想使用的角度表单验证我的形式,博客文章,并且更具体地是NG-禁用的形式。至于原因,我无法弄清楚未禁用按钮,在那里,它应该是,除非所有三个输入字段是有效的提交。谢谢您的帮助。
这是我的博客模板
< DIV NG控制器='BlgoCtrl'>
< DIV CLASS ='集装箱'>
< H1> Teewinot Blgo< / H1>
< DIV CLASS =行>
< DIV CLASS ='COL-MD-12'>
<形式的作用=形式的名字='blgoPost'NOVALIDATE>
< DIV CLASS ='的形式组'>
<标签='blgoTitle'>标题< /标签>
<输入名称=标题类型=题类='的形式控制'占位符=所需&GT未来技术;< BR>
<标签='blgoContent'>内容< /标签>
< textarea的名字='内容'行=8TYPE =内容类='的形式控制'占位符='未来的技术创新将是多样化和影响力对个人......需要&GT ;< / textarea的>< BR>
<标签='blgoPass code'>通code< /标签>
<输入名称='通code'型=通code类='的形式控制 placeholder='•••••••••••••••'要求>< BR>
<按钮式=提交类='BTN BTN-小学'NG-禁用=$ blgoPost无效。>提交邮政和LT; /按钮>
< / DIV>
< /表及GT;
< / DIV>
< / DIV>
下面是我的index.html
<!DOCTYPE HTML>
< HTML LANG =ENGT&;
< HEAD>
<间的charset =UTF-8>
<标题> Teewinot< /标题> &所述; SCRIPT SRC =bower_components /角度/ angular.js>&下; /脚本> <脚本SRC =bower_components / jQuery的/距离/ jquery.js和>< / SCRIPT>
<脚本SRC =bower_components /引导/距离/ JS / bootstrap.js>< / SCRIPT>
< META NAME =视口CONTENT =WIDTH =设备宽度,初始规模= 1.0>
<脚本SRC =bower_components /角路由/角route.js>< / SCRIPT>
<链接HREF =bower_components /引导/距离/ CSS / bootstrap.css的rel =stylesheet属性>< /头><机身NG-应用=Teewinot>
< NG-包括SRC =应用程序/模板/谐音/ navbar.html'>< / NG-包括>< NG-视图>< / NG-视图>
&所述;! - 角模块确定指标和reoutes - >
<脚本SRC =应用程序/ JS / app.js>< / SCRIPT>
<脚本SRC =应用程序/ JS / routes.js>< / SCRIPT>
<! - 控制器 - >
<脚本SRC =应用程序/ JS /控制器/ blog.controller.js>< / SCRIPT>< /身体GT;
< / HTML>
这是我的博客控制器
angular.module('Teewinot')。控制器('BlgoCtrl',函数($范围,$ HTTP){
使用严格
});
您错过 NG-模型
在表单的各个领域。请记住,当你提到 NG-模型
在那时 NG-模型
任何形式的领域创建里面的额外的对象与该特定名称
属性,然后考虑表格名称对象,而表单验证像 $误差
, $有效
, $无效
等
随着你的表格名称
是 blgoPost
,当角编译该页面时,它在内部创建范围内的对象 blgoPost
的名称。和所有的输入字段有名称
&安培; NG-模型
分配给他们, blgoPost
对象中得到补充。但是,如果你不提 NG-模型
来的表单字段,然后它永远不会在 blgoPost
表单中得到补充对象。
HTML
<形式的作用=形式的名字='blgoPost'NOVALIDATE =>
<输入名称=第一个/>
< DIV CLASS ='的形式组'>
<标签='blgoTitle'>标题< /标签>
<输入名称=标题类型=题类='的形式控制'NG模型=测试1占位符=所需=&GT未来技术;
< BR>
<标签='blgoContent'>内容< /标签>
< textarea的名字='内容'行=8TYPE =内容NG模型=test2的类='的形式控制'占位符='未来的技术创新将是多样的和有影响力的个人。 .....'所需=>< / textarea的>
< BR>
<标签='blgoPass code'>通code< /标签>
<输入名称='通code'型=通codeNG-模式=TEST3类='的形式控制'占位符='和;#8226;&放大器;#8226;&安培; #8226所必需的'=/>
< BR />
<按钮式=提交类='BTN BTN-小学'NG-禁用=$ blgoPost无效。>提交邮政和LT; /按钮>
< / DIV>
< /表及GT;
I am trying to use the angular form validations in my form for a blog post, and more specifically a ng-disabled form. For reasons I cannot figure out the submit button is not disabled, where as it should be unless all three input fields are valid. Thanks for the help.
this is my blog template
<div ng-controller='BlgoCtrl'>
<div class='container'>
<h1> Teewinot Blgo</h1>
<div class="row">
<div class='col-md-12'>
<form role='form' name='blgoPost' novalidate>
<div class='form-group'>
<label for='blgoTitle'>Title</label>
<input name='title' type="title" class='form-control' placeholder='Technologies of the Future' required><br>
<label for='blgoContent'>Content</label>
<textarea name='content' rows='8' type="content" class='form-control' placeholder='The technical innovations of the future will be diverse and impactful on the individual......' required></textarea><br>
<label for='blgoPassCode'>PassCode</label>
<input name='passcode' type="passcode" class='form-control' placeholder='•••••••••••••••' required><br>
<button type="submit" class='btn btn-primary' ng-disabled="blgoPost.$invalid">Submit Post</button>
</div>
</form>
</div>
</div>
Here is my index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Teewinot</title>
<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/jquery/dist/jquery.js"></script>
<script src="bower_components/bootstrap/dist/js/bootstrap.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="bower_components/angular-route/angular-route.js"></script>
<link href="bower_components/bootstrap/dist/css/bootstrap.css" rel="stylesheet">
</head>
<body ng-app="Teewinot">
<ng-include src="'app/templates/partials/navbar.html'"></ng-include>
<ng-view></ng-view>
<!-- angular module defintion and reoutes -->
<script src="app/js/app.js"></script>
<script src="app/js/routes.js"></script>
<!-- controllers -->
<script src="app/js/controllers/blog.controller.js"></script>
</body>
</html>
This is my blog controller
angular.module('Teewinot').controller('BlgoCtrl', function($scope, $http) {
'use strict'
});
You're missing ng-model
on every field of your form. Keep in mind when you mention ng-model
on any form field at that time ng-model
creates the extra objects inside form name object with that specific name
attribute which then considered while form validation like $error
, $valid
, $invalid
, etc.
As your form name
is blgoPost
, when angular compile this page,it internally creates the object inside the scope of the name of blgoPost
. And the all the input fields which has name
& ng-model
assign to them gets added inside that blgoPost
object. But if you don't mention ng-model
to the form fields then it will never get added inside the blgoPost
form object.
HTML
<form role='form' name='blgoPost' novalidate="">
<input name="first" />
<div class='form-group'>
<label for='blgoTitle'>Title</label>
<input name='title' type="title" class='form-control' ng-model="test1" placeholder='Technologies of the Future' required="">
<br>
<label for='blgoContent'>Content</label>
<textarea name='content' rows='8' type="content" ng-model="test2" class='form-control' placeholder='The technical innovations of the future will be diverse and impactful on the individual......' required=""></textarea>
<br>
<label for='blgoPassCode'>PassCode</label>
<input name='passcode' type="passcode" ng-model="test3" class='form-control' placeholder='•••' required="" />
<br/>
<button type="submit" class='btn btn-primary' ng-disabled="blgoPost.$invalid">Submit Post</button>
</div>
</form>
这篇关于角表单验证NG-禁用不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!