Open rdehuyss opened 8 years ago
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.
@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.
Marking this as enhancement to expose require config or come up with better idea.
@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 :confused:
I hope this help as the comment was from few months ago.
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: :confused:]
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 https://github.com/ngUpgraders/ng-forward/issues/146#issuecomment-210386859
Where can I find an example using the Directive annotation to create a custom validator?
Awesome project by the way!