Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit 0cc1217

Browse files
matskomhevery
authored andcommitted
fix(NgForm): use map notation for controls and dot notation for instance properties
1 parent fd7ad68 commit 0cc1217

File tree

2 files changed

+20
-48
lines changed

2 files changed

+20
-48
lines changed

lib/directive/ng_form.dart

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ part of angular.directive;
2222
publishTypes : const <Type>[NgControl],
2323
map: const { 'ng-form': '@name' },
2424
visibility: NgDirective.CHILDREN_VISIBILITY)
25-
class NgForm extends NgControl implements Map<String, NgControl> {
25+
class NgForm extends NgControl {
2626
/**
2727
* Instantiates a new instance of NgForm. Upon creation, the instance of the
2828
* class will be bound to the formName property on the scope (where formName
@@ -57,56 +57,10 @@ class NgForm extends NgControl implements Map<String, NgControl> {
5757
}
5858
}
5959

60-
//FIXME: fix this reflection bug that shows up when Map is implemented
61-
operator []=(String key, value) {
62-
if (key == 'name') {
63-
name = value;
64-
} else {
65-
_controlByName[key] = value;
66-
}
67-
}
68-
69-
//FIXME: fix this reflection bug that shows up when Map is implemented
70-
operator[](name) {
71-
if (name == 'valid') {
72-
return valid;
73-
} else if (name == 'invalid') {
74-
return invalid;
75-
} else {
76-
return _controlByName[name];
77-
}
78-
}
79-
80-
bool get isEmpty => false;
81-
bool get isNotEmpty => !isEmpty;
82-
get values => null;
83-
get keys => null;
84-
get length => null;
85-
clear() => null;
86-
remove(_) => null;
87-
containsKey(_) => false;
88-
containsValue(_) => false;
89-
addAll(_) => null;
90-
forEach(_) => null;
91-
putIfAbsent(_, __) => null;
60+
NgControl operator[](name) => _controlByName[name];
9261
}
9362

9463
class NgNullForm extends NgNullControl implements NgForm {
9564
NgNullForm() {}
96-
9765
operator[](name) {}
98-
operator []=(String name, value) {}
99-
100-
bool get isEmpty => false;
101-
bool get isNotEmpty => true;
102-
get values => null;
103-
get keys => null;
104-
get length => null;
105-
clear() => null;
106-
remove(_) => null;
107-
containsKey(_) => false;
108-
containsValue(_) => false;
109-
addAll(_) => null;
110-
forEach(_) => null;
111-
putIfAbsent(_, __) => null;
11266
}

test/directive/ng_form_spec.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,24 @@ void main() {
483483
}));
484484
});
485485

486+
it("should use map notation to fetch controls", inject((TestBed _) {
487+
Scope s = _.rootScope;
488+
s.context['name'] = 'cool';
489+
490+
var form = _.compile('<form name="myForm">' +
491+
' <input type="text" ng-model="someModel" probe="i" name="name" />' +
492+
'</form>');
493+
494+
NgForm formModel = s.context['myForm'];
495+
Probe probe = s.context['i'];
496+
var model = probe.directive(NgModel);
497+
498+
expect(s.eval('name')).toEqual('cool');
499+
expect(s.eval('myForm.name')).toEqual('myForm');
500+
expect(s.eval('myForm["name"]')).toBe(model);
501+
expect(s.eval('myForm["name"].name')).toEqual("name");
502+
}));
503+
486504
describe('regression tests: form', () {
487505
it('should be resolvable by injector if configured by user.', () {
488506
module((Module module) {

0 commit comments

Comments
 (0)