Multiple directives [arValidations, datepickerPopup] asking for new/isolated scope on...

47 views
Skip to first unread message

Alex Cips

unread,
Apr 14, 2015, 4:50:22 PM4/14/15
to ang...@googlegroups.com
Reposting this question http://stackoverflow.com/questions/29636120/multiple-directives-arvalidations-datepickerpopup-asking-for-new-isolated-sco

I can think about workarounds but nothing simple. I feel there has to be a simpler way to get the same result.. it s just input validations.

Sander Elias

unread,
Apr 14, 2015, 11:15:05 PM4/14/15
to ang...@googlegroups.com
Hi Alex,

Why aren't you adding your validator(s) to ngModel.$validators? You are adding a lot of overhead + an extra watcher that is not really needed.

Regards
Sander


Sander Elias

unread,
Apr 15, 2015, 1:49:07 AM4/15/15
to ang...@googlegroups.com
Hi Alex,

As an addition to my other reply.
If you need multiple directives with each of them their own private stuff, create directives with controllers. For validation you don't need to sue $scope at all, but instead interface with ngModelController directly.
have a look at this directive example I created yesterday. It uses ngModel to get/set the scope variable, without ever touching the scope. The only time it uses scope is to propagate a new 'keyboard' to the view.
I use a $digest in there because there are only directive-local changes, and nothing else can be touched. 

Regards
Sander


Alex Cips

unread,
Apr 15, 2015, 3:07:18 PM4/15/15
to ang...@googlegroups.com
I didn't like the default validators so I built my own. The workaround I found was to build a custom datepicker directive that includes the 3rd party datepicker directive and adds validations to it.

Sander Elias

unread,
Apr 16, 2015, 2:38:51 AM4/16/15
to ang...@googlegroups.com
Hi Alex

You can add your OWN validators in there. you don't need tu use the default ones.
your code is mimicking the exact same thing as the error-handler of angular.

Regards
Sander
Reply all
Reply to author
Forward
0 new messages