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

Switch RTL/LTR on production with angular-cli according to variable in global window object #984

Closed
Mostafa-Rady opened this issue Oct 9, 2017 · 3 comments

Comments

@Mostafa-Rady
Copy link

commented Oct 9, 2017

I've an app which is multi-lang using angular-cli, need to be able to switch RTL/LTR on production
I don't know how to dynamically change the RTL/LTR, I've tried this but is not working
let useValue=window['someValue']; // true or false according to active user settings
providers: [
{provide: RTL, useValue: useValue}
]
assigning useValue from a flag from the window object but it doesn't change the output when reloading the page, style keeps RTL always while the value has changed has false,
please provide me with the way of how to do it properly

@tsvetomir tsvetomir added the Question label Oct 10, 2017
@tsvetomir

This comment has been minimized.

Copy link
Member

commented Oct 10, 2017

Changes to the provided value will not be reflected with useValue.
You need to use a factory provider to dynamically resolve values.

@Mostafa-Rady

This comment has been minimized.

Copy link
Author

commented Oct 10, 2017

Thanks for your reply,
I added this factory function
export function enableRTL() {
if (window['dirConfig'] && window['dirConfig'].isRtl) {
return RTL;
}
return null;
}
And added
providers: [
{provide: RTL, useFactory: enableRTL}
]
It worked but not sure if this is the best way to do it

@tsvetomir

This comment has been minimized.

Copy link
Member

commented Oct 10, 2017

That would do it, although the token value should be a boolean.

Please note that this repository is for bug reports only. Please open a support ticket if you'd like assistance with project-specific inquiries.

@tsvetomir tsvetomir closed this Oct 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.