2017-07-25 94 views
1

當在按鈕中使用ng-click時,IE遇到問題。 我想從彈簧控制器重新加載數據,只要用戶點擊在Chrome中工作正常的按鈕,但不在IE11中。 問題是當頁面加載數據顯示在網頁上時,單擊刷新數據按鈕時,它將通過點擊彈出控制器來重新加載數據,而該控制器在IE中不工作。在IE中,當用戶點擊一個按鈕時,它將觸及角度控制器以及服務方法,但不會觸及彈簧控制器。但是當開發人員工具打開時,它將觸及彈簧控制器。下面在IE11中測試時無法擊中彈簧控制器

實施例: HTML代碼:

<div ng-controller="loadingSampleCtrl"> 
     <button class="btn btn-primary" type="button" ng-click="loadOrRefreshData()">Reload</button> 
{{myData.empName}} /* This is printed in chrome as well as in IE with developer tools opened*/ 
    </div> 

js代碼:

myApp.controller('loadingSampleCtrl', function ($scope, MyService) { 
    $scope.loadData = function() { 
    $scope.loading = true; 
     MyService.testData().then(
      function (response) { 
       alert("response back from spring controllerf"); 
       if(window.navigator.msSaveOrOpenBlob){ 
        $scope.IEBrowser = true; 
        $scope.myData = response; 
        /* $timeout(function() { 
        $scope.pdfName = response; 
        }, 0);*/ 
       } else { 
        $scope.IEBrowser = false; 
        $scope.myData = response; 
       } 
      }, 
      function (errResponse) { 
       $rootScope.showError("Internal error" + errResponse); 
      }); 
    } 
    $scope.testData(); 
}); 

//service call 
    _myService.testData = function(){ 
      alert("service call");//this alert is visible in IE 
      var deferred = $q.defer(); 
     var repUrl = myAppURL+'/myDataToRead/getData.form'; 
     $http.get(repUrl).then(
       function (response) { 
        deferred.resolve(response.data); 
       }, 
       function(errResponse){ 

        deferred.reject(errResponse); 
       } 
      ); 
     return deferred.promise; 
    } 

彈簧控制器:

@RequestMapping(value = "/getData", method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE) 
    public @ResponseBody 
    List<String> getMyData(HttpServletRequest request) throws Exception { 
     System.out.println("In MyDataController"); //not printed in IE when tested without developer tools 
    //logic here 
    //return statement 
} 

任何建議將是有幫助的。

+0

任何一個人都面臨同樣的問題,如上所述? – DIM

+0

不明白爲什麼在'service'中創建的URL與爲Spring控制器聲明的'@ RequestMapping'不匹配。該URL應該是'var repUrl = myAppURL +'/ getData';'。在調用彈簧控制器時,還要檢查IE開發人員有關記錄錯誤的工具 –

回答

0

我檢查你的網址var repUrl = yAppURL+'/myDataToRead/getData.form';,我這個問題是你是不是地圖控制器的路徑。你只能用/getData來映射你的方法。您需要在控制器中使用@RequestMapping註釋。你可以參考下面的代碼:

@RestController 
@RequestMapping("/myDataToRead")