-
Notifications
You must be signed in to change notification settings - Fork 109
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
Using angular services #54
Comments
As a workaround, you should be able to pass them into the viewmodel, something like |
Hi @shturminator! You have 3 options: Option 1: Simply // factory.js
myApp.factory('apiToken', ['clientId', function apiTokenFactory(clientId) {
var encrypt = function(data1, data2) {
return (data1 + ':' + data2).toUpperCase();
};
var secret = window.localStorage.getItem('myApp.secret');
var apiToken = encrypt(clientId, secret);
return apiToken;
}]); You can update that to: // factory.js
var encrypt = function(data1, data2) {
return (data1 + ':' + data2).toUpperCase();
};
var secret = window.localStorage.getItem('myApp.secret');
export var apiToken = encrypt(clientId, secret);
myApp.factory('apiToken', ['clientId', function apiTokenFactory(clientId) {
return apiToken;
}]); Then from your React component, simply import Option 2 is what @Sawtaytoes suggested. Just DI your service/factory, and pass it to your React component as a regular prop. Option 3 Once #49 is merged, DI will be supported out of the box. |
With v3.1.0, you can now use the extended DI syntax: react2angular(Component, props, providersToDI) See example in the docs. |
Great!. Thank you for a solution.
On Monday, December 11, 2017, 7:23:07 PM GMT+2, Boris Cherny <[email protected]> wrote:
With v3.1.0, you can now use the extended DI syntax:
react2angular(Component, props, providersToDI)
See example in the docs.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
What if we add |
@Sawtaytoes Yes, just tell react2angular to infer props from propTypes by passing class A {}
A.propTypes = {..}
let B = react2angular(A, null, ['$http', '$log']) |
Could you please suggest an approach to use sevices/factories inside react2angular component?
Thanks.
The text was updated successfully, but these errors were encountered: