我正在做一些使用angular的输入验证,但是当函数被调用时,每个元素都会返回为undefined。我在下面列出了重要的代码,请让我知道这是不够的。我感谢任何帮助,我可以得到。TypeError:undefined不是函数输入验证AngularJS
JS
angular.module('app.directives', [])
.directive('mrnCheck', [function() {
return {
require: 'ngModel',
link: function (scope, elem, attrs, ctrl) {
//console.log(firstMRN.val());
var firstMRN = '#' + attrs.mrnCheck;
elem.add('test');
//console.log(firstMRN.val());
//console.log(firstMRN);
elem.add(firstMRN).on('keyup', function() {
scope.$apply(function() {
ctrl.$setValidity('mrnmatch', elem.val() === $(firstMRN).val());
});
});
}
}
}]);
HTML
<div class = "row" ng-show="<?php echo $_SESSION["associate"]; ?>">
</br>
<form name = "UploadForm" class="input-group" role="form">
<div class="input-group">
<span class="input-group-addon">MRN</span>
<input type="MRN" ng-model="MRN1" class="form-control" id="MRN1" placeholder="Patient MRN" ng-required="" />
</div>
</br>
<div class="input-group">
<span class="input-group-addon">MRN</span>
<input type="MRN" ng-model="MRN2" class="form-control" id="MRN2" placeholder="Confirm MRN" ng-required="" mrn-Check="MRN1" />
<span ng-show="UploadForm.MRN2.$error.MRNmatch">MRN values must match!</span>
</div>
</form>
</div>
错误
在链路(httpsomeLink/imageinbox/IIExpress /应用/ app.js:237:9) 在nodeLinkFn(httpsomeLink/imageinbox/IIExpress /应用程序/资产/ (httpsomeLink/imageinbox/IIExpress/app/assets/angular/angular.js:6704:13) at compositeLinkFn(httpsomeLink/imageinbox/IIExpress/app/assets/angular/angular.js:6098:13) 在nodeLinkFn(httpsomeLink/imageinbox/IIExpress/app/assets/angul上的angular.js:6101:13) (httpsomeLink/imageinbox/IIExpress/app/assets/angular/arg.js:6698:24) at compositeLinkFn(httpsomeLink/imageinbox/IIExpress/app/assets/angular/angular.js:6098:13) (httpsomeLink/imageinbox/IIExpress/app/assets/angular/angular。)中的compositeLinkFn(httpsomeLink/imageinbox/IIExpress/app/assets/angular/angular.js:6098:13) 。 js:6101:13) at nodeLinkFn(httpsomeLink/imageinbox/IIExpress/app/assets/angular/angular.js:6698:24)
请注意,第237行是以elem.add开头的行。此外,某些链接代表一个真实的链接,因为我无法发布真正的链接。
你能设置一个提琴手吗?同时指定从控制台 – Moiz 2014-12-08 08:24:09
完整的错误当然,我听说过它,但不是很熟悉。哪些数据对你有用? – aProgrammer 2014-12-08 08:25:20
从控制台复制完整。例如在链接之前应该会出现一些错误 – Moiz 2014-12-08 08:27:14