【问题标题】:AngularJS dindn't work in firefoxAngularJS 在 Firefox 中不起作用
【发布时间】:2017-02-08 07:33:12
【问题描述】:

我为 Web 应用程序编写了登录信息。在 chrome 中登录有效,但在 Firefox 中无效。

<form ng-submit="$ctrl.login()">
   <div class="cClearFloat">
      <input type="text" name="Benutzername" placeholder="Benutzername" ng-model="$ctrl.userName">
   </div>
      <div class="cClearFloat">
         <input type="password" name="Passwort" placeholder="Passwort" ng-model="$ctrl.password">
      </div>
      <div class="cClearFloat">
         <div class="cButtonLogin" class="button">
            <button class="cLinkLogin" type="submit">Anmelden</button>
         </div>
      </div>
</form>

登录调用:

login() {
    this.userService.login(this.userName, this.password);
}

登录:

login(userName, password) {
   this.$http.post("http://localhost:20670/login", { UserName: userName, Password: password }).then((response) => {
      this.userInfo = this.hateoasService.fromData(response.data);
      this.$http.defaults.headers.common.LoginToken = this.userInfo.LoginToken;
      this.isLoggedIn = true;
}, (response) => {
   swal({
      title: response.data.error,
      type: 'error'
   })
 });
}

当我在 Firefox 中测试它时发生的所有事情都是它重新加载页面。有人知道为什么它不起作用吗?是否有可能重新加载是因为 angularjs 不可用并且他从 ng-submit 中获取默认值?

在我的控制台中我遇到了这个错误

【问题讨论】:

  • 我曾经使用过
    Anmelden 或类似的东西。
  • 查看您的控制台错误,错误不在您的表单中,而是在某些对象调用中。请检查您的控制台错误的堆栈跟踪。
  • 堆栈跟踪用于 angular.min.js 文件
  • 然后使用非缩小角度进行调试。这些堆栈跟踪将更具描述性

标签: angularjs google-chrome firefox


【解决方案1】:

在您的form 上使用ng-submit 并将按钮类型更改为submit

在你看来:

<div ng-app="myApp" ng-controller="myCtrl">
    <form ng-submit="login()">
        <input type="text" name="Benutzername" placeholder="Benutzername" ng-model="model.userName">
        <input type="password" name="Passwort" placeholder="Passwort" ng-model="model.password">
        <button class="cLinkLogin" type="submit">Anmelden</button>
    </form>
</div>

在控制器上:

var app = angular.module("myApp", []);
app.controller("myCtrl", myCtrl);

function myCtrl($scope) {
    $scope.model = {};
    $scope.login = function() {
        alert("username: " + $scope.model.userName + ", password: " + $scope.model.password);
    }
}

http://codepen.io/anon/pen/dNgvJp?editors=1010

【讨论】:

    猜你喜欢
    • 2017-08-30
    • 1970-01-01
    • 1970-01-01
    • 2015-05-03
    • 1970-01-01
    • 2012-11-27
    • 2012-02-27
    • 2017-02-08
    • 2014-08-23
    相关资源
    最近更新 更多