Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/directive/ng_control.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
part of angular.directive;

abstract class NgControl implements NgDetachAware {
abstract class NgControl implements NgAttachAware, NgDetachAware {
static const NG_VALID_CLASS = "ng-valid";
static const NG_INVALID_CLASS = "ng-invalid";
static const NG_PRISTINE_CLASS = "ng-pristine";
Expand Down Expand Up @@ -38,10 +38,17 @@ abstract class NgControl implements NgDetachAware {
_scope.on('submitNgControl').listen((e) => _onSubmit(e.data));
}

@override
attach() {
_parentControl.addControl(this);
}

@override
detach() {
for (int i = _controls.length - 1; i >= 0; --i) {
removeControl(_controls[i]);
}
_parentControl.removeControl(this);
}

reset() {
Expand Down Expand Up @@ -70,7 +77,6 @@ abstract class NgControl implements NgDetachAware {
get name => _name;
set name(value) {
_name = value;
_parentControl.addControl(this);
}

get element => _element;
Expand Down
17 changes: 17 additions & 0 deletions test/directive/ng_form_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,23 @@ void main() {
expect(form['two']).toBeNull();
expect(form['three']).toBeNull();
}));

it('should remove from parent when child is removed', inject((Scope scope, TestBed _) {
var element = $('<form name=myForm">' +
' <input type="text name="mega_name" ng-if="mega_visible" />' +
'</form>');
_.compile(element);

scope.context['mega_visible'] = true;
scope.apply();

var form = scope.context['myForm'];
expect(form['mega_name']).toBeDefined();

scope.context['mega_visible'] = false;
scope.apply();
expect(form['mega_name']).toBeNull();
}));
});

describe('onSubmit', () {
Expand Down