Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/401.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 角型JS&;输入类型_Javascript_Angularjs - Fatal编程技术网

Javascript 角型JS&;输入类型

Javascript 角型JS&;输入类型,javascript,angularjs,Javascript,Angularjs,我当前的版本有一个非常奇怪的问题。(Angular版本1.2.16) 控制器: app.controller('recoverController', function( $scope, $rootScope, $http, $window, $cookies, $state ){ $scope.recoverAddress = 'hello'; }); 视图: 作品: <input type="text" ng-model

我当前的版本有一个非常奇怪的问题。(Angular版本1.2.16)

控制器:

app.controller('recoverController', function(
    $scope, 
    $rootScope, 
    $http, 
    $window,
    $cookies,
    $state
){

    $scope.recoverAddress = 'hello';
});
视图:

作品:

<input type="text" ng-model="recoverAddress" />

失败:

<input type="email" ng-model="recoverAddress" />

仅当输入字段中的值通过验证时,AngularJS才会绑定到模型。一旦您提供了一个有效的电子邮件地址模型,就会绑定、更新观察者等。这就是angular的工作原理 只需输入有效的电子邮件


{{emailInput}}
函数testCtrl($scope){
$scope.$watch('emailInput',函数(newValue){
console.log(newValue);
});
}

您收到的是错误还是空白?干杯!通过将hello改为hello@me.com,输入类型为按预期填充的电子邮件。但是,我仍然无法从视图中更新模型。例如,如果我删除了初始化recoverAddress的语句,然后输入了一封有效的电子邮件,点击submit,它仍然会在控制台中将其记录为未定义
<div ng-app ng-controller="testCtrl">
    <input ng-model="emailInput" type="email">
    <div>{{emailInput}}</div>
</div>

function testCtrl($scope) {
    $scope.$watch('emailInput', function(newValue){
        console.log(newValue);
    });
}