Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 安格拉斯<;输入>;不包含任何附件的验证<;表格>;_Angularjs_Validation - Fatal编程技术网

Angularjs 安格拉斯<;输入>;不包含任何附件的验证<;表格>;

Angularjs 安格拉斯<;输入>;不包含任何附件的验证<;表格>;,angularjs,validation,Angularjs,Validation,是否可以在角度上以与表单验证类似的方式验证单个孤立的?我在想这样的事情: <div class="form-group"> <input name="myInput" type="text" class="form-control" ng-model="bindTo" ng-maxlength="5"> <span class="error" ng-show="myInput.$error.maxlength">Too long!</sp

是否可以在角度上以与表单验证类似的方式验证单个孤立的
?我在想这样的事情:

<div class="form-group">
    <input name="myInput" type="text" class="form-control" ng-model="bindTo" ng-maxlength="5">
    <span class="error" ng-show="myInput.$error.maxlength">Too long!</span>
</div>

太久了!
上面的例子不起作用。将其包含在
中,并将
ng show
替换为
ng show=“myForm.myInput.$error.maxlength”
会有所帮助


不使用
是否可以执行此操作?

您可以使用ng form angular指令()对任何内容进行分组,即使在html表单之外。然后,您可以利用angular FormController

<div class="form-group" ng-form name="myForm">
    <input name="myInput" type="text" class="form-control" ng-model="bindTo" ng-maxlength="5">
    <span class="error" ng-show="myForm.myInput.$error.maxlength">Too long!</span>
</div>

太久了!


安古拉斯普朗克
文件。写(“”);
要求的
所需名称
你好{{name}}

名字
var app=angular.module('plunker',[]); 应用程序控制器('MainCtrl',函数($scope){ $scope.name='World'; $scope.field=“name”; $scope.firstName=“firstName”; $scope.execute=function(){ 警报(‘已执行’); } });

基于Silvio Lucas的答案,如果您在循环中迭代,并且需要能够插入表单名称和有效状态:

<div
  name="{{propertyName}}"
  ng-form=""
  class="property-edit-view"
  ng-class="{
    'has-error': {{propertyName}}.editBox.$invalid,
    'has-success':
      {{propertyName}}.editBox.$valid &&
      {{propertyName}}.editBox.$dirty &&
      propertyValue.length !== 0
  }"
  ng-switch="schema.type">
  <input
    name="editBox"
    ng-switch-when="int"
    type="number"
    ng-model="propertyValue"
    ng-pattern="/^[0-9]+$/"
    class="form-control">
  <input
    name="editBox"
    ng-switch-default=""
    type="text"
    ng-model="propertyValue"
    class="form-control">
  <span class="property-type" ng-bind="schema.type"></span>
</div>


您试过了吗?但我不认为是这样,我相信Angular会在后台创建一个
表单。FormController
跟踪表单的输入状态,比如
有效\无效&肮脏\原始。
供将来的读者使用,他们也希望在按钮的ng click事件中验证这样的表单,请参见此处:带有单个验证的多个输入示例@SilvioLucas-即使字段为空,您的示例仍然“执行”?这有什么不同吗?如果是这样的话,你能补充一个解释它的区别吗?以及解释?
<div
  name="{{propertyName}}"
  ng-form=""
  class="property-edit-view"
  ng-class="{
    'has-error': {{propertyName}}.editBox.$invalid,
    'has-success':
      {{propertyName}}.editBox.$valid &&
      {{propertyName}}.editBox.$dirty &&
      propertyValue.length !== 0
  }"
  ng-switch="schema.type">
  <input
    name="editBox"
    ng-switch-when="int"
    type="number"
    ng-model="propertyValue"
    ng-pattern="/^[0-9]+$/"
    class="form-control">
  <input
    name="editBox"
    ng-switch-default=""
    type="text"
    ng-model="propertyValue"
    class="form-control">
  <span class="property-type" ng-bind="schema.type"></span>
</div>