NgModel class
Ng-model directive is responsible for reading/writing to the model. The directive itself is headless. (It does not know how to render or what events to listen for.) It is meant to be used with other directives which provide the rendering and listening capabilities. The directive itself knows how to convert the view-value into model-value and vice versa by allowing others to register converters (To be implemented). It also knwos how to (in)validate the model and the form in which it is declared (to be implemented)
@NgDirective( selector: '[ng-model]', map: const {'ng-model': '&model'}) class NgModel { final Scope _scope; Getter getter = ([_]) => null; Setter setter = (_, [__]) => null; String _exp; Function _removeWatch = () => null; bool _watchCollection; Function render = (value) => null; NgModel(Scope this._scope, NodeAttrs attrs) { _exp = 'ng-model=${attrs["ng-model"]}'; watchCollection = false; } get watchCollection => _watchCollection; set watchCollection(value) { if (_watchCollection == value) return; _watchCollection = value; _removeWatch(); if (_watchCollection) { _removeWatch = _scope.$watchCollection((s) => getter(), (value) => render(value), _exp); } else { _removeWatch = _scope.$watch((s) => getter(), (value) => render(value), _exp); } } set model(BoundExpression boundExpression) { getter = boundExpression; setter = boundExpression.assign; } // TODO(misko): right now viewValue and modelValue are the same, // but this needs to be changed to support converters and form validation get viewValue => modelValue; set viewValue(value) => modelValue = value; get modelValue => getter(); set modelValue(value) => setter(value); }
Constructors
new NgModel(Scope _scope, NodeAttrs attrs) #
Creates a new Object instance.
Object instances have no meaningful state, and are only useful through their identity. An Object instance is equal to itself only.
docs inherited from Object
NgModel(Scope this._scope, NodeAttrs attrs) { _exp = 'ng-model=${attrs["ng-model"]}'; watchCollection = false; }
Properties
dynamic set model(BoundExpression boundExpression) #
set model(BoundExpression boundExpression) { getter = boundExpression; setter = boundExpression.assign; }
var modelValue #
get modelValue => getter();
set modelValue(value) => setter(value);
Function render #
Function render = (value) => null
var viewValue #
get viewValue => modelValue;
set viewValue(value) => modelValue = value;
var watchCollection #
get watchCollection => _watchCollection;
set watchCollection(value) { if (_watchCollection == value) return; _watchCollection = value; _removeWatch(); if (_watchCollection) { _removeWatch = _scope.$watchCollection((s) => getter(), (value) => render(value), _exp); } else { _removeWatch = _scope.$watch((s) => getter(), (value) => render(value), _exp); } }