简体   繁体   English

AngularJS输入URL无效/有效/错误

[英]AngularJS input url invalid/valid/error

I've a mistake with input type url in angularjs. 我在angularjs中输入类型的网址有误。 I would disable the button if input is empty or invalid and I wrote the code below. 如果输入为空或无效,我将禁用该按钮,并在下面编写了代码。 Well, it's fine on the first time o if I write an incorrect url but if it's empty propForm.imgUrl.$invalid and propForm.imgUrl.$error.url it returns me false and this enable click of button 好吧,如果我输入的网址不正确,那么第一次还是可以的,但是如果它是空的propForm.imgUrl。$ invalid和propForm.imgUrl。$ error.url,它会返回false并启用按钮单击

    <div class="col-sm-10">
          <input type="url" name="imgUrl" ng-model="$parent.urlImage" class="form-control">
            </div>
                <div class="pull-right col-sm-2">
                   <a href="" class="btn btn-default btn-primary" ng-disabled="propForm.imgUrl.$invalid || propForm.imgUrl.$pristine || propForm.imgUrl.$error.url" ng-click="addImage()">Add</a>
                 </div>

Where is the trick?a 诀窍在哪里?

The quickest way is adding required to input please see demo below. 最快的方法是添加requiredinput请参阅下面的演示。

 var app = angular.module('app', []); app.controller('homeCtrl', function($scope) { }); 
 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" type="text/css" /> <div ng-app="app"> <div ng-controller="homeCtrl"> <form name="propForm"> <div class="col-sm-10"> <input type="url" name="imgUrl" ng-model="$parent.urlImage" class="form-control" required> </div> <div class="pull-right col-sm-2"> <a href="" class="btn btn-default btn-primary" ng-disabled="propForm.imgUrl.$invalid || propForm.imgUrl.$pristine || propForm.imgUrl.$error.url" ng-click="addImage()">Add</a> </div> </form> </div> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AngularJS输入监视$ valid或$ error - AngularJS input watch $valid or $error 基础遵守-如果先前输入无效,则触发有效输入上的无效错误 - Foundation Abide - Triggers invalid error on valid inputs if a prior input is invalid 为AngularJS中的无效输入字段实现错误类 - Implementing an Error-Class for an invalid input field in AngularJS 我的angularjs表单上的$ invalid和$ valid都未定义 - $invalid and $valid on my angularjs form are both undefined 当输入在angularjs中有效时添加类 - add class when input is valid in angularjs 角材料设计有效/无效输入 - Angular material design valid/invalid input 重复无效的用户输入,直到有效为止(伪) - Repeat invalid user input until it is valid (pseudo) 带有angularjs的有效输入掩码(ui-mask) - Valid input mask with angularjs (ui-mask) UnhandledPromiseRejectionWarning:错误:协议错误(Page.navigate):当我传递有效的 URL 时无法导航到无效的 URL - UnhandledPromiseRejectionWarning: Error: Protocol error (Page.navigate): Cannot navigate to invalid URL when I am passing valid URLS 如何基于AngularJS输入类设置Twitter Bootstrap class = error = ng-invalid? - How to set Twitter Bootstrap class=error based on AngularJS input class=ng-invalid?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM