2016-06-09 57 views
1

我有嵌套在控制器內的角指令元素,我得到這個消息角指令得到「主線程同步的XMLHttpRequest已過時」

同步XMLHttpRequest的主線程在其有害的,因爲已經過時影響最終用戶的體驗。如需更多幫助,請查詢https://xhr.spec.whatwg.org/。 警告:試圖加載角度不止一次。

我有點明白它是什麼意思,但我不知道是什麼導致了這個問題。下面是我有:

audio.html

<div class="audio-top-bar" ng-controller="AudioController"> 
    <div class="audio-tuner-button" ng-click="displayTunerModal()"> 
      <button class="btn"> 
       <p class="audio-tuner-type">{{tunerButton}}</p> 
      </button> 
    </div> 
    <display-tuner-modal ng-show="visibility"></display-tuner-modal> 
</div> 

AudioController.js

angular.module('app').controller('AudioController', ['$scope', 'TunerService', function($scope, TunerService){ 
    $scope.visibility = false; 

    if ($scope.tunerButton == (null || undefined)) 
     $scope.tunerButton = 'FM'; 
    $scope.displayTunerModal = function(){ 
     $scope.visibility = true; 
    }; 
}]); 

displayTunerModal.js

angular.module('app').directive('displayTunerModal', ['TunerService' , function (TunerService){ 

    return { 
     restrict: 'E', 
     link: function(scope, elem, attrs){ 
      scope.displayTunerModal = function(){ 
       console.log("CLICKED"); 
      }; 
     }, 
     templateUrl: 'public/templates/displayScreenModal.html' 
    }; 
}]); 
+1

顯示的代碼中沒有任何內容與Ajax有關,這就是XMLHttpRequest被稱爲的內容。 – charlietfl

+0

我的問題很簡單,就像鏈接名稱不正確一樣簡單。我應該有「displayTunerModal.html」。 –

回答

0

我很抱歉,這個問題很簡單,就像在指令中的鏈接名稱不正確一樣。我應該有「displayTunerModal.html」。

道德故事:檢查你的鏈接。

0

this question我在AngularJS指令相同Synchronous XMLHttpRequest on the main thread is deprecated生產服務器上,而對我當地環境沒有這樣的錯誤。

在此我的情況是因情況不匹配模板名稱VS爵士請求:

  • AngularJS(在我的境遇指令)的請求小寫mytemplate.tmpl.html
  • 模板文件與駝峯命名爲: myTemplate.tmpl.html

什麼困惑的問題是,指令/模板(由於OSX case-insensitivity)工作的罰款在Mac上 - 但是,當推到了一個Linux case-sensitive AWS親失敗管理服務器。

將模板文件名更改爲小寫修復了問題。

正如上面的評論之一所述,AJAX錯誤是誤導性的,因爲它暗示特定調用有什麼問題,而不僅僅是文件「缺失」。

+1

請不要將[相同的答案](http://stackoverflow.com/a/42128191/5292302)添加到多個問題。回答最好的一個,並將其餘標記爲重複。請參閱[是否可以爲幾個問題添加重複答案?](http://meta.stackexchange.com/questions/104227/is-it-acceptable-to-add-a-duplica te-answer-to-幾個問題) –

+0

@PetterFriberg請在進行此調用之前閱讀(並理解)兩個問題。它們不是重複的問題,因此不能標記爲這樣。這是一個令人困惑的編碼錯誤(錯誤的措辭/誤導性的錯誤信息)浪費了我一大堆時間,所以我將解決方案放在兩個問題中 - 因爲這個答案是針對兩種(稍微不同)情況的特定解決方案。另外,我將這個答案中的原始答案問題(透明度和實用性)聯繫起來。 – goredwards