Skip to content
This repository has been archived by the owner on Jul 28, 2019. It is now read-only.

Using a directive inside a React component #49

Closed
marekkalnik opened this issue Mar 2, 2015 · 9 comments
Closed

Using a directive inside a React component #49

marekkalnik opened this issue Mar 2, 2015 · 9 comments

Comments

@marekkalnik
Copy link
Contributor

Hi,

I'm trying to check if it is possible to use directives inside a react component.

The naive approach (just keeping the directive in the JSX) is obviously not working. So I tried to inject the scope and compile the directive by myself, but it seems that injecting the whole scope is not possible. Do you have any idea if it is doable? If not, I think it would be nice to mention it in the documentation, as it may be an important reason to avoid using React.

@kasperp
Copy link
Collaborator

kasperp commented Mar 2, 2015

Hi @marekkalnik Thanks for you question. Do you mean to use an existing angular directive inside a React Component?

ngReact kind of does the opposite. I think of it as taking a part of an angular view and turning it into a React view (component). You can can use existing angular injectables as described in the README. So it is possible to share code between an angular directive and a React Component, but you'll need to make the functionality you which to share available as e.g. an angular service.

Did that answer your question, if not please let me know if I misunderstood you.

@marekkalnik
Copy link
Contributor Author

Yes. The idea is to use React but still keep the directives like ui-sref
working. This would speed up the migration, even if it may be suboptimal on
the performance level.

If the only thing we can reuse are services it would mean that some
directives would need a bit of refactoring to be reintegrated in React.
Le 2 mars 2015 21:02, "Kasper Bøgebjerg Pedersen" notifications@github.com
a écrit :

Hi @marekkalnik https://github.com/marekkalnik Thanks for you question.
Do you mean to use an existing angular directive inside a React Component?

ngReact kind of does the opposite. I think of it as taking a part of an
angular view and turning it into a React view (component). You can can use
existing angular injectables as described in the README
https://github.com/davidchang/ngReact#reusing-angular-injectables. So
it is possible to share code between an angular directive and a React
Component, but you'll need to make the functionality you which to share
available as e.g. an angular service.

Did that answer your question, if not please let me know if I
misunderstood you.


Reply to this email directly or view it on GitHub
#49 (comment).

@kasperp
Copy link
Collaborator

kasperp commented Mar 3, 2015

Yeah I can see that it would speed up migration if it was possible. It is as you found out not and I'm not exactly sure it could work.

@marekkalnik
Copy link
Contributor Author

@kasperp ok, thank you very much for your anwsers. I think it should be just a bit clearer in the documentation. I'll submit à PR.

@kasperp
Copy link
Collaborator

kasperp commented Mar 9, 2015

yeah we could improve til docs in this regards. Thanks

@monah-abouassi
Copy link

Hi All,
I would like to know if any changes has been made since this PR is submitted.
Thank you

@kasperp
Copy link
Collaborator

kasperp commented Nov 30, 2015

@monah-abouassi sorry I don't understand your question.

@monah-abouassi
Copy link

Hi
I am sorry I didn’t clarify my question I would like to know if it s possible at least to load the html file of the directive so we do not have code duplication and the functions will be written in a different service.
Thank you

@kasperp
Copy link
Collaborator

kasperp commented Nov 30, 2015

okay the discussion around support directives inside components is on #120, but no nothing have been completed yet.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants