我将 angular.js 用于小型应用程序。在用户填写数据并单击submit
按钮后的注册页面中,从控制器调用一种方法,该方法进行 API 调用,然后在下一页重定向用户。这在 Chrome、Firefox 和 Microsoft Edge 中运行良好,但在 Internet Explorer 中无法运行。
这是我的signup.html
<form name="userRegForm"
ng-submit="userRegForm.$valid && registerUser()">
<md-input-container class="md-block">
<label>Full name</label>
<input required
ng-model="user.fullName"
name="fullName"
id="fullName"
autocomplete="off"
ng-pattern="/^[a-zA-Z ]*$/">
<div ng-messages="userRegForm.fullName.$error">
<div ng-message="required">Full name is required.</div>
<div ng-message="pattern">Please enter valid name</div>
</div>
</md-input-container>
<md-input-container class="md-block">
<label>Email</label>
<input required name="emailId" ng-model="user.emailId" type="email" autocomplete="off">
<div ng-messages="userRegForm.emailId.$error">
<div ng-message="required">Email is required.</div>
<div ng-message="email">Please enter valid Email.</div>
</div>
</md-input-container>
<md-input-container class="md-block">
<label>Password</label>
<input required name="password" ng-model="user.password" type="password" autocomplete="off">
<div ng-messages="userRegForm.password.$error">
<div ng-message="required">Password is required.</div>
</div>
</md-input-container>
<section id="non-padding" style="overflow: hidden">
<div class='layout layout--middle'>
<div class="layout__item xs-mb1 sm-text-right xs-text-right col-xs-4 sm-5of12 xs-6of12 sm-push7of12 sm-mb0 padding-right-0">
<input placeholder="REGISTER" type="submit" class="button button button--primary"
value="SIGN UP">
</div>
</div>
</section>
</form>
这是我的controller
$scope.registerUser = function () {
apiUrl = "http://example.com/save_data";
var userData = {
role: 'CANDIDATE',
fullName: $scope.user.fullName,
emailId: $scope.user.emailId.toLowerCase(),
password: $scope.user.password
};
webService.sendPostRequest(apiUrl, userData,
function (response) {
data = JSON.parse(response.data);
if (data.RESPONSE_CODE == 'SUCCESS') {
$state.go('restricted.candidate.editProfile', {pageId: ''}, {location: 'replace'});
} else if (data.RESPONSE_CODE == 'WARNING') {
alertService.setNotification('Email already exists.', 'warning');
alertService.showNotification();
} else {
alertService.setNotification('Something going wrong, Please try again.', 'failure');
alertService.showNotification();
}
},
function (err) {
alertService.setNotification('Something went wrong, Please try again.', 'failure');
alertService.showNotification();
}
);
};
此代码在所有其他浏览器中运行良好,但不仅在 Internet Explorer 中(我有 v11,Windows 10)。
我在这个问题上有很多谷歌,但有些答案说替换ng-click="function_name()"
为直接ng-click="$state.go()"
,但这在我的情况下不起作用。
谢谢