我正在做一些使用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