This repository has been archived by the owner on Feb 22, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(forms): provide support for controls and state flags
- Loading branch information
Showing
5 changed files
with
388 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,24 +11,41 @@ part of angular.directive; | |
* (to be implemented) | ||
*/ | ||
@NgDirective( | ||
selector: '[ng-model]', | ||
map: const {'ng-model': '&model'}) | ||
selector: '[ng-model]') | ||
class NgModel { | ||
final NgForm _form; | ||
final dom.Element _element; | ||
final Scope _scope; | ||
|
||
Getter getter = ([_]) => null; | ||
Setter setter = (_, [__]) => null; | ||
|
||
String _exp; | ||
String _name; | ||
|
||
bool _dirty; | ||
bool _pristine; | ||
bool _valid; | ||
bool _invalid; | ||
|
||
Function _removeWatch = () => null; | ||
bool _watchCollection; | ||
|
||
Function render = (value) => null; | ||
|
||
NgModel(this._scope, NodeAttrs attrs) { | ||
NgModel(this._scope, NodeAttrs attrs, [dom.Element this._element, NgForm this._form]) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
mhevery
Contributor
|
||
_exp = 'ng-model=${attrs["ng-model"]}'; | ||
watchCollection = false; | ||
|
||
_form.addControl(this); | ||
pristine = true; | ||
} | ||
|
||
@NgAttr('name') | ||
get name => _name; | ||
set name(value) { | ||
_name = value; | ||
_form.addControl(this); | ||
} | ||
|
||
get watchCollection => _watchCollection; | ||
|
@@ -43,6 +60,7 @@ class NgModel { | |
} | ||
} | ||
|
||
@NgCallback('ng-model') | ||
set model(BoundExpression boundExpression) { | ||
getter = boundExpression; | ||
setter = boundExpression.assign; | ||
|
@@ -55,6 +73,43 @@ class NgModel { | |
|
||
get modelValue => getter(); | ||
set modelValue(value) => setter(value); | ||
|
||
get pristine => _pristine; | ||
set pristine(value) { | ||
_pristine = true; | ||
_dirty = false; | ||
_element.classes.remove(NgForm.NG_DIRTY_CLASS); | ||
_element.classes.add(NgForm.NG_PRISTINE_CLASS); | ||
} | ||
|
||
get dirty => _dirty; | ||
set dirty(value) { | ||
_dirty = true; | ||
_pristine = false; | ||
_element.classes.remove(NgForm.NG_PRISTINE_CLASS); | ||
_element.classes.add(NgForm.NG_DIRTY_CLASS); | ||
} | ||
|
||
get valid => _valid; | ||
set valid(value) { | ||
_invalid = false; | ||
_valid = true; | ||
_element.classes.remove(NgForm.NG_INVALID_CLASS); | ||
_element.classes.add(NgForm.NG_VALID_CLASS); | ||
} | ||
|
||
get invalid => _invalid; | ||
set invalid(value) { | ||
_valid = false; | ||
_invalid = true; | ||
_element.classes.remove(NgForm.NG_VALID_CLASS); | ||
_element.classes.add(NgForm.NG_INVALID_CLASS); | ||
} | ||
|
||
|
||
destroy() { | ||
_form.removeControl(this); | ||
} | ||
} | ||
|
||
/** | ||
|
Oops, something went wrong.
May I ask what purpose optional parameters in the constructor fulfill for injected types?
I haven't found information how DI handles them.