Thanks Majid for your feedback. Your post contains very valuable
information for me. I'll get my head in to your suggestions.
I have also found out in the meantime that certain functions such as
$timeout will trigger a digest cycle. So if I wrap the scope.oldValue in
to $timeout then it'll do a digest cycle before and will display the
value. Not that I want to use it this way but it helped to understand
that also a push to $parsers seems to trigger a digest cycle so that I
can be sure that scope.oldValue will be resolved by then.
The quick wins are great with Angular but boy that's deep diving in to
code to learn the tricky parts. A few more real world examples would
come in handy. The books usually also stop to dive deep at some point. I
think I'll still end up in some headache. But I'm staying with Angular.
As far as I have evaluated AngularJS is the most mature thing/framework
out there compared to others and once I'm able to write re-usable
widgets using directives I think I'll be really happy.....
hopefully :)
angular.module('eaValidators', [])
.directive('eaValidateEmailUnique', ['$timeout', function($timeout)
{
return {
restrict: 'A',
require: '?ngModel',
link: function(scope, elem, attr, ctrl) {
if (!ctrl) return;
// email regex for validation
var regex
= /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
var url = attr.eaValidateEmailUnique;
scope.$watch(attr.ngModel, function(value) {
if(angular.isDefined(value)) {
// save the current value as the same value can
be saved
scope.oldValue = value;
}
});
$timeout(function() {
console.log("Value inside timeout: " +
scope.oldValue);
}, 0);
return true;
}
};
}]);
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "AngularJS" group.
> To unsubscribe from this topic, visit
>
https://groups.google.com/d/topic/angular/ZcA4eOttQzA/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
>
angular+u...@googlegroups.com.
> To post to this group, send email to
ang...@googlegroups.com.
> Visit this group at
http://groups.google.com/group/angular.
> For more options, visit
https://groups.google.com/groups/opt_out.