1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AngularJSでValidationをかけたインプット項目に、invalidになる値を初期値として入れると値が見えなくなる

Last updated at Posted at 2014-07-11

どうも見えなくなるどころか、値が入っていないらしい。

バインドしたモデル自体は書き換えられていない。

aj.valueMissing.html
<!DOCTYPE html>
<html lang="ja"><head><meta charset="utf-8" /></head>
<body>
<div ng-app="app" ng-controller="validCtrl">
<form name="form" novalidate>
  <input ng-model="default" ng-minlength="7" id="invalidDefault" name="default"/>{{ form.default.$error }}
  <p>default:{{ default }}</p>
  <p>invalidDefault.value:<span id="output"></span></p>
  <script>
    setInterval(function(){output.innerHTML = invalidDefault.value},5);
  </script>
</form>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.js"></script>
<script>
var app = angular.module('app', []);
app.controller('validCtrl',['$scope',function ($scope) {
  $scope.default = '123456';
  setTimeout(function(){$scope.default='78945677';$scope.$apply();},3000);
  setTimeout(function(){$scope.default='415647';$scope.$apply();},6000);
}]);
</script>
</body></html>

後からバインドしたモデルの変更を行った時も値を消されてしまう。

今は特に困ってないけど、解決方法がわからないとつらいシーンが訪れるかもしれない。

1
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?