2017-07-25 49 views
0

我正在使用angularjs应用程序。我在我的主页上有一个按钮,当用户点击按钮时,它必须击中控制器,并从后端获取数据并显示在浏览器上。一切工作正常在铬和Firefox但不能在IE中工作。试图很难找到一个替代解决方案来解决,但没有运气,任何建议都会有所帮助。替代按钮ng-click in angularjs

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陈述未打印

+1

你能告诉我这是点击按钮,btnAdminDetails函数正在运行吗?或不? –

+0

是的它也在运行并调用角度控制器,问题是它没有打到弹簧控制器。 – user7833845

+1

请向我们展示您的MyService代码。 –

回答

-1

有ngClick没有这样的选择,但你也可以使用ngDblClick到位ngClick的更多详细信息,请参考以下链接:按钮标记内

https://docs.angularjs.org/api/ng/directive/ngClick

+0

我的问题是不是一个替代方案,但应该在IE中工作,显然我不能使用ngDblClick,因为我不能说用户双击获取功能,而不是一个单一的点击按钮。任何建议对我以上的职位相关将是有益的。@ Mayank Sharma – user7833845

0

增加价值

<div ng-controller="myController"> 
    <button type="submit" class="btn btn-default" value="login" ng- 
    click="btnAdminDetails()"> 
     Login 
    </button> 
</div> 
+0

我已经尝试添加,但没有运气。我现在正在编辑我的最新版本。请看看 – user7833845

+0

Whats是您使用的IE版本 –

+0

IE11是版本,控制台中没有显示任何错误。 @Vikash库马尔 – user7833845

0

我认为你的应用程序在IE11中无法正常工作,请按照以下步骤进行修改。

1.增加在头标记

<meta http-equiv="X-UA-Compatible" content="IE=11" /> 

以下行2,采用严格的模式,你的控制器

(function() { 
    "use strict"; 

    function yourController($scope, $rootScope) { 
     // Do things 
    } 

}()); 

3.Change对于web.config文件到IE11

<?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>