This repository was archived by the owner on Feb 22, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -57,14 +57,18 @@ class NgForm extends NgControl {
57
57
}
58
58
}
59
59
60
+ get controls => _controlByName;
61
+
60
62
NgControl operator [](name) {
61
- if (_controlByName .containsKey (name)) {
62
- return _controlByName [name][0 ];
63
+ if (controls .containsKey (name)) {
64
+ return controls [name][0 ];
63
65
}
64
66
}
65
67
}
66
68
67
69
class NgNullForm extends NgNullControl implements NgForm {
68
70
NgNullForm () {}
69
71
operator [](name) {}
72
+
73
+ get controls => null ;
70
74
}
Original file line number Diff line number Diff line change @@ -40,6 +40,30 @@ void main() {
40
40
expect (scope.eval ("myForm['model']" )).toBe (one);
41
41
}));
42
42
43
+ it ('should return the all the controls with the given name' , inject ((Scope scope, TestBed _) {
44
+ var element = $('<form name="myForm">' +
45
+ ' <input type="text" name="model" ng-model="modelOne" probe="a" />' +
46
+ ' <input type="text" name="model" ng-model="modelTwo" probe="b" />' +
47
+ '</form>' );
48
+
49
+ _.compile (element);
50
+ scope.apply ();
51
+
52
+ NgForm form = _.rootScope.context['myForm' ];
53
+ NgModel one = _.rootScope.context['a' ].directive (NgModel );
54
+ NgModel two = _.rootScope.context['b' ].directive (NgModel );
55
+
56
+ expect (one).not.toBe (two);
57
+
58
+ var controls = form.controls['model' ];
59
+ expect (controls[0 ]).toBe (one);
60
+ expect (controls[1 ]).toBe (two);
61
+
62
+ expect (scope.eval ("myForm.controls['model'][0]" )).toBe (one);
63
+ expect (scope.eval ("myForm.controls['model'][1]" )).toBe (two);
64
+ }));
65
+
66
+
43
67
describe ('pristine / dirty' , () {
44
68
it ('should be set to pristine by default' , inject ((Scope scope, TestBed _) {
45
69
var element = $('<form name="myForm"></form>' );
You can’t perform that action at this time.
0 commit comments