回答編集履歴
1
a
test
CHANGED
@@ -1,4 +1,82 @@
|
|
1
1
|
ng-initは不要で ng-model="article.name"として下さい。
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
```html
|
6
|
+
|
7
|
+
<html ng-app="myApp">
|
8
|
+
|
9
|
+
<head>
|
10
|
+
|
11
|
+
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular.min.js"></script>
|
12
|
+
|
13
|
+
<script>
|
14
|
+
|
15
|
+
angular.module('myApp', []).controller('MyController', ['$scope', function($scope) {
|
16
|
+
|
17
|
+
$scope.articles = [
|
18
|
+
|
19
|
+
{title:'テラテイル', name: '質問', site: 'https://teratail.com'},
|
20
|
+
|
21
|
+
];
|
22
|
+
|
23
|
+
}]);
|
24
|
+
|
25
|
+
</script>
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
</head>
|
30
|
+
|
31
|
+
<body ng-controller="MyController">
|
32
|
+
|
33
|
+
<form name="myForm" ng-submit="onsubmit()" novalidate>
|
34
|
+
|
35
|
+
<div ng-repeat="article in articles">
|
36
|
+
|
37
|
+
{{article.title}}<br>
|
38
|
+
|
39
|
+
<label for="name">名前:</label><br />
|
40
|
+
|
41
|
+
<input id="name" name="name" type="text" ng-model="article.name" required ng-minlength="2" ng-maxlength="10" />
|
42
|
+
|
43
|
+
<span ng-show="myForm.name.$error.required">
|
44
|
+
|
45
|
+
名前は必須です。</span>
|
46
|
+
|
47
|
+
<span ng-show="myForm.name.$error.minlength">
|
48
|
+
|
49
|
+
名前は2文字以上で入力してください。</span>
|
50
|
+
|
51
|
+
<span ng-show="myForm.name.$error.maxlength">
|
52
|
+
|
53
|
+
名前は10文字以内で入力してください。</span><br />
|
54
|
+
|
55
|
+
<label for="url">URL:</label><br />
|
56
|
+
|
57
|
+
<input id="url" name="site" type="url" ng-model="article.site" required />
|
58
|
+
|
59
|
+
<span ng-show="myForm.site.$error.required">
|
60
|
+
|
61
|
+
urlは必須です。</span>
|
62
|
+
|
63
|
+
<span ng-show="myForm.site.$error.url">
|
64
|
+
|
65
|
+
urlは正しい形式で入力してください。</span>
|
66
|
+
|
67
|
+
</div>
|
68
|
+
|
69
|
+
<input type="submit" value="申込"
|
70
|
+
|
71
|
+
ng-disabled="myForm.$invalid" />
|
72
|
+
|
73
|
+
</form>
|
74
|
+
|
75
|
+
</body>
|
76
|
+
|
77
|
+
</html>
|
78
|
+
|
79
|
+
```
|
2
80
|
|
3
81
|
|
4
82
|
|