Skip to content

Commit

Permalink
#113 removed isolated scope
Browse files Browse the repository at this point in the history
  • Loading branch information
Nazanin1369 committed Nov 29, 2015
1 parent 6f6698e commit 2943b6f
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/validator.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
var $validationProvider = $injector.get('$validation');
var $q = $injector.get('$q');
var $timeout = $injector.get('$timeout');
var $parse = $injector.get('$parse');

/**
* Do this function if validation valid
Expand Down Expand Up @@ -159,14 +160,14 @@
return {
restrict: 'A',
require: 'ngModel',
scope: {
model: '=ngModel',
initialValidity: '=initialValidity',
validCallback: '&',
invalidCallback: '&',
messageId: '@'
},
scope: true,
link: function(scope, element, attrs, ctrl) {
var getValidCallBack = $parse('success');
var getInvalidCallBack = $parse('error');
scope.messageId = attrs.messageId;
scope.validCallback = getValidCallBack(scope.$parent);
scope.invalidCallback = getInvalidCallBack(scope.$parent);

/**
* watch
* @type {watch}
Expand Down Expand Up @@ -248,9 +249,9 @@
if (attrs.validMethod === 'submit') {
// clear previous scope.$watch
watch();
watch = scope.$watch('model', function(value, oldValue) {
value = ctrl.$viewValue;

watch = scope.$watch(function() {
return scope.$eval(attrs.ngModel);
}, function(value, oldValue) {
// don't watch when init
if (value === oldValue) {
return;
Expand Down Expand Up @@ -288,7 +289,7 @@
*/
if (attrs.validMethod === 'blur') {
element.bind('blur', function() {
var value = ctrl.$viewValue;
var value = scope.$eval(attrs.ngModel);
scope.$apply(function() {
checkValidation(scope, element, attrs, ctrl, validation, value);
});
Expand All @@ -308,8 +309,9 @@
* Validate watch method
* This is the default method
*/
scope.$watch('model', function(value) {
value = ctrl.$viewValue;
scope.$watch(function() {
return scope.$eval(attrs.ngModel);
}, function(value) {
/**
* dirty, pristine, viewValue control here
*/
Expand Down

0 comments on commit 2943b6f

Please sign in to comment.