Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Adding ngModel. #2904

Closed
wants to merge 1 commit into from
Closed
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
23 changes: 21 additions & 2 deletions src/ng/directive/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,23 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
parentForm.$setValidity(validationErrorKey, isValid, this);
};

/**
* @ngdoc function
* @name ng.directive:ngModel.NgModelController#setContext
* @methodOf ng.directive:ngModel.NgModelController
*
* @description
* Sets the context where the attr.ngModel expression has be getted/setted
* Useful for isolated directives wich uses ngModel expresion from the parent scope
*
*/
var modelContext = $scope;

this.$setContext = function(context) {
modelContext = context;
console.log('context setted', context);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps you should send with this in a comment.

}

/**
* @ngdoc function
* @name ng.directive:ngModel.NgModelController#$setPristine
Expand Down Expand Up @@ -1043,7 +1060,7 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$

if (this.$modelValue !== value) {
this.$modelValue = value;
ngModelSet($scope, value);
ngModelSet(modelContext, value);
forEach(this.$viewChangeListeners, function(listener) {
try {
listener();
Expand All @@ -1058,7 +1075,9 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
var ctrl = this;

$scope.$watch(function ngModelWatch() {
var value = ngModelGet($scope);
//Allways context is scope
//var value = ngModelGet($scope);
var value = ngModelGet(modelContext);

// if scope model value and ngModel value are out of sync
if (ctrl.$modelValue !== value) {
Expand Down