Angular的ngmodel只在firefox/https中不更新$scope

Angular ngmodel not updating $scope in firefox/https only

本文关键字:更新 scope https ngmodel 只在 firefox Angular      更新时间:2023-09-26

我有一个登录表单,它使用ng-model将数据传递给控制器。当调用ng-submit时,我将此数据传递给服务器以验证用户。

然而,仅在Firefox中,并且仅在我们的活动(https)服务器上,模型值永远不会更新。使用console.log($scope.loginform)只是打印默认值:

{ username="", password=""}

在开发中(http),当使用Chrome时,它正确地更新它们与输入的值:

{ username="kermit", password="noteasybeinggreen"}

这是我的表单,jade格式
form(method='post',ng-submit='login()')
    ol
        li
            label(class='icon-user')
            input(type='text',name='username',ng-model='loginform.username',placeholder='Username')
        li
            label(class='icon-key')
            input(type='password',name='password',ng-model='loginform.password',placeholder='Password',class='pass')
        li
            input(type='submit',class='pressable',value='Login')

我的控制器:

.controller('LoginController', ['$scope','$http','$stateParams',function($scope,$http,$stateParams) {
    $scope.loginform = {
        username: '',
        password: ''
    };
    $scope.login = function() {
        console.log( 'login called: ', $scope.loginform );
        $http.post('/login', $scope.loginform).success(function(resp, status, headers, config) {
            // stuff
        })
        .error(function(resp, status, headers, config){
            // stuff
        });
    };
}]);

有什么我错过了,做错了,等等?我不明白为什么只有火狐。

本页目前在https://pste.me/#/login

我找到原因了。

似乎当浏览器自动填充用户名/密码字段时,ng-model不会更新。

请参考AngularJS浏览器自动填充解决方案,使用指令来解决可能的问题。