Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Example for Custom Validator using directive annotation #146

Open
rdehuyss opened this issue Feb 10, 2016 · 5 comments
Open

Example for Custom Validator using directive annotation #146

rdehuyss opened this issue Feb 10, 2016 · 5 comments

Comments

@rdehuyss
Copy link

Where can I find an example using the Directive annotation to create a custom validator?

Awesome project by the way!

@rdehuyss
Copy link
Author

Some more info: all the angular1 validators use the link function in the directive. From what I understand from the documentation: link and compile are not set and are not able to be set.

Also, we need access to ngModel which I don't see how we can access.

@timkindberg
Copy link
Contributor

@directive actually runs it's class instance against the link function so we are good there. We even have a local that you can inject called $requires but I'm not seeing a way to specify the actual requires in the @directive config. I think the injectable $requires is left over from when the code base was previously called angular-decorators before we refactored it to be ng-forward. We would have to add the ability to add require to the config. That shouldn't be too difficult, but it's low priority because there is a workaround. You can still use normal angular 1 to declare a new module with your directive and then include the module into the providers array of one of your ng-forward components.

@timkindberg timkindberg added this to the Milestone 3 milestone Feb 10, 2016
@timkindberg
Copy link
Contributor

Marking this as enhancement to expose require config or come up with better idea.

@esaiz
Copy link

esaiz commented Apr 15, 2016

@rdehuyss you can inject the ngModel to add your validators. I have a directive to check if two fields are equal. You can check the gist here https://gist.github.com/esaiz/1bf0236e92b0dea9d5906b9a8d81a860

I follow the example you can find in the playground app https://github.com/ngUpgraders/ng-forward-playground/blob/master/app/directives/FocusOn.js

To access the value from the template I had to use $attrs because the @input and @output are not working in the directives with ng-forward (there is another issue open about this)

In the template I had to use the old angular 1 syntax to bind the value 😕

I hope this help as the comment was from few months ago.

@rdehuyss
Copy link
Author

Hi Esteban, thx for the feedback - your solution is definitely better than
ours. We implemented a angular 1 validator in the end which we now use.
We'll look into how to migrate to your solution.

Thx again!

On Fri, Apr 15, 2016 at 11:40 AM, Esteban Saiz notifications@github.com
wrote:

@rdehuyss https://github.com/rdehuyss you can inject the ngModel to add
your validators. I have a directive to check if two fields are equal. You
can check the gist here
https://gist.github.com/esaiz/1bf0236e92b0dea9d5906b9a8d81a860

I follow the example you can find in the playground app
https://github.com/ngUpgraders/ng-forward-playground/blob/master/app/directives/FocusOn.js

To access the value from the template I had to use $attrs because the
@input https://github.com/Input and @output https://github.com/Output
are not working in the directives with ng-forward (there is another issue
open about this)

In the template I had to use the old angular 1 syntax to bind the value [image:
😕]

I hope this help as the comment was from few months ago.


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#146 (comment)

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

3 participants