我正在开发angularjs应用程序。我的主页上有一个按钮,当用户点击按钮时,它必须点击控制器,然后从后端获取数据并在浏览器上显示。在chrome和firefox中一切正常,但在IE中无法正常工作。很难找到一个替代解决方案来解决,但没有运气,任何建议都会有所帮助。
html: 登录
spring controller:
@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"); //printed only when navigated through chrome
//logic here
//return statement
}
PS:当在IE11中执行相同的上述代码时,它没有击中弹簧控制器,但工作正常是chrome和safari。什么可以是实现与按钮在angularjs中相同的功能的替代方式,并且在IE和Chrome中都可以使用。
- EDITED-- js控制器:
myApp.controller('myController', function ($scope, MyService) {
$scope.btnAdminDetails= function () {
alert("In btnAdminDetails, js controller"); //this is called both in IE11 and chrome
console.log("In controller");
MyService.retrieveData().then(
function (response) {
alert("response back from spring controller");
if(window.navigator.msSaveOrOpenBlob){
$scope.IEBrowser = true;
$scope.myData = response;
} else {
$scope.IEBrowser = false;
$scope.myData = response;
}
},
function (errResponse) {
$rootScope.showError("Internal error" + errResponse);
});
}
$scope.btnAdminDetails();
});
//service code
_myService.retrieveData= function(){
alert("service call");//called when tested from both IE and chrome, but issue is from IE the java controller is not getting called from here..
console.log("In Angular Service above $q.defer ");
var deferred = $q.defer();
console.log("In Angular Service below $q.defer");
var randomh=Math.random();
var repUrl = myAppURL+'/myControllerr/getData.form?x='+randomh+"";
$http.get(repUrl).then(
function (response) {
deferred.resolve(response.data);
},
function(errResponse){
deferred.reject(errResponse);
}
);
return deferred.promise;
}
I have added Math.random to the request URL in the service call.
在IE11中,当我单击按钮时,仅显示控制器中的警告btnAdminDetail, js controller
,其他警报语句或console.log语句不会打印。
答案 0 :(得分:0)
在按钮标记
中添加值<div ng-controller="myController">
<button type="submit" class="btn btn-default" value="login" ng-
click="btnAdminDetails()">
Login
</button>
</div>
答案 1 :(得分:0)
我认为您的应用程序无法在IE11中运行。请执行以下更改。
1.在标题
中添加以下行<meta http-equiv="X-UA-Compatible" content="IE=11" />
2.使用控制器的严格模式
(function () {
"use strict";
function yourController($scope, $rootScope ) {
// Do things
}
}());
3.更改关于IE11的web.config文件
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<httpProtocol>
<customHeaders>
<clear />
<add name="X-UA-Compatible" value="IE=11" />
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>
答案 2 :(得分:-1)
没有ngClick的替代品,但您也可以使用ngDblClick代替ngClick了解更多详情,请参阅此链接: