Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Accessing the error state in another directive #7

Closed
nathanmarks opened this issue Sep 21, 2017 · 3 comments
Closed

Accessing the error state in another directive #7

nathanmarks opened this issue Sep 21, 2017 · 3 comments
Labels

Comments

@nathanmarks
Copy link

nathanmarks commented Sep 21, 2017

I have a custom input-container component which implements error class toggling in a similar way that the material form field component does -- by accessing a directive attached to the input inside, which in turn gets the error state from NgControl.

I wanted to do a similar thing for ngrx-forms via the NgrxFormControlDirective but the state and stateSubject properties and the state$ getter are both private, meaning I can't get the state of the input from the container component.

Is there a workaround for this? Or do I have to add an input to my input directive taking the form control state object and use that instead?

@MrWolfZ
Copy link
Owner

MrWolfZ commented Sep 21, 2017

@nathanmarks I'll add an item to my TODO list to make the state property public. In the meantime there's two ways you can do this:

  1. simply access the state property by casting the directive to any after injecting it (private doesn't exist at runtime so you can still access the value)
  2. add an @Input() ngrxFormControlState binding to your own component (this will always get the same value as the ngrx-forms directive has)

@nathanmarks
Copy link
Author

Thanks, I went with the casting for now.

@MrWolfZ
Copy link
Owner

MrWolfZ commented Oct 28, 2017

@nathanmarks With a recent bugfix I made the state property public (see 8cc65d7). Once the next version is released (which should happen either this or next weekend) you'll have access to the state without the casting trick.

@MrWolfZ MrWolfZ closed this as completed Oct 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants