0
我有一個非常奇怪的問題,只是偶爾出現。有時當我加載我的頁面時,在控制檯中出現以下錯誤。然後,我可以重新加載網站,一切工作正常。AnuglarJs - ReferenceError:錯誤未定義 - 重新加載頁面可解決錯誤
angular.js:12520 ReferenceError: errors is not defined
at eval (eval at <anonymous> (https://code.jquery.com/jquery-1.10.2.min.js:4:4994), <anonymous>:1:13)
at eval (<anonymous>)
at https://code.jquery.com/jquery-1.10.2.min.js:4:4994
at Function.globalEval (https://code.jquery.com/jquery-1.10.2.min.js:4:5005)
at init.domManip (https://code.jquery.com/jquery-1.10.2.min.js:5:28160)
at init.append (https://code.jquery.com/jquery-1.10.2.min.js:5:25581)
at init.<anonymous> (https://code.jquery.com/jquery-1.10.2.min.js:5:27127)
at Function.access (https://code.jquery.com/jquery-1.10.2.min.js:4:6690)
at init.html (https://code.jquery.com/jquery-1.10.2.min.js:5:26701)
at https://example.com/app1//Scripts/angular-ui-router.min.js:7:27884 <div ui-view="" class="ng-scope">
我不知道確切位置的錯誤發生,但我有一個ng-form
,我跟蹤我認爲是源代碼錯誤。奇怪的是,它大部分時間都在工作,如果發生錯誤,我必須重新加載頁面並重新開始工作。有誰之前經歷過這個嗎?
<ng-form name="validationForm">
<ng-form name="companyDetails">
<!-- inputs and other controls here -->
</ng-form>
<ng-form name="paymentInformation">
<!-- inputs and other controls here -->
</ng-form>
<div ng-repeat="(key, errors) in validationForm.companyDetails.$error track by $index" class="text-muted">
<p><b>Wrong input in company details:</b></p>
<p style="margin-left: 20px;" ng-repeat="e in errors">
- {{e.$name}}
</p>
</div>
<div ng-repeat="(key, errors) in validationForm.paymentInformation.$error track by $index" class="text-muted">
<p>
<b>
Wrong input in payment information:
<script>console.log(errors)</script>:
</b>
</p>
<p style="margin-left: 20px;" ng-repeat="e in errors">
- {{e.$name}}
</p>
</div>
</ng-form>
發佈驅動標記的JS。 – GillesC
在首次加載頁面時,錯誤似乎是「未定義的」。在觸發'ng-repeat'之前,你需要確保它不是'undefined'。 – AndreaM16
您可以嘗試從您的視圖中刪除嵌套。流內容,但沒有表單元素的後代 - 參考https://www.w3.org/TR/html5/forms.html#the-form-element –