-
-
Notifications
You must be signed in to change notification settings - Fork 21
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
Custom Props Support #41
Comments
Hi @mancioshell - good question. single-spa-angularjs currently does not pass the props down to angularjs applications, but I'd be very open to adding that. In other helper libraries, we've passed the single-spa props down as props to React/Vue component. However, in single-spa-angularjs there is only a Perhaps the ideal would be adding the single-spa props to While you're waiting for that PR, you can get the single-spa props by providing a second, custom mount lifecycle: import singleSpaAngularJS from 'single-spa-angularjs';
import angular from 'angular';
const ngLifecycles = singleSpaAngularJS({
angular: angular,
mainAngularModule: 'app',
uiRouter: true,
preserveGlobal: false,
template: '<my-component />',
});
export const bootstrap = ngLifecycles.bootstrap;
export const mount = [
function (singleSpaProps) {
return Promise.resolve().then(function() {
console.log('single-spa props', singleSpaProps)
})
},
ngLifecycles.mount
];
export const unmount = ngLifecycles.unmount; |
This is now avaialbe in https://github.com/single-spa/single-spa-angularjs/releases/tag/v3.2.0. You can access the props via the following: $rootScope.singleSpaProps |
Hi @joeldenning thank you for your support.
The strange things is, when i try to console.log $rootScope i see singleSpaProps in chrome console. |
The following commit shows that it works - polyglot-microfrontends/account-settings@bd2a378. And you can see the singleSpaProps by checking the browser console at https://polyglot.microfrontends.app/settings My code change to single-spa-angularjs adds the singleSpaProps to rootScope after angular.bootstrap() is called. It is possible that |
It works for me if i inject $rootScope directly in a controller, but is undefined if i inject it in a service (using service or privider api). |
I doubt that that is related to single-spa-angularjs (although I'm happy to be proven wrong 😄), and would guess that you have some issues in your angular code that is attempting to use them in the ajax function. Since single-spa props is defined on the $rootScope, you can do whatever you'd like with it, including injecting it into the DI namespace via |
One thing with the single-spa props is that they are only initialized once the single-spa application is mounted - if you attempt to access them before the application is mounted, they won't be present. |
HI @joeldenning, thank you for all your work... I have a question related to this case... what about using props in an angularjs component? I'm using this to isolate an old component, and I'm wondering if it is possible to pass the props in a component way to be able to reuse my bindings (input and outputs):
Thanks :) |
I have to say that I've found the exactly same problem of @mancioshell... the
|
Here's a code sandbox that shows how: https://codesandbox.io/s/serverless-river-0cm9r?file=/index.html You can access the single spa props in templates via <div>{{ $root.singleSpaProps.token }}</div> I discovered a way to make sure that the application is rerendered when the props are set, and will submit a PR with that. |
The fix I mentioned above is released in https://github.com/single-spa/single-spa-angularjs/releases/tag/v4.2.3 |
In case any one else still has issues: With the code fragments below, the
It was a bit of a goose chase, since Regardless, I was able to work-around the issue with a small addition to the template of the main module. By adding
I'm by no means an AngularJS expert; but me and a colleague had a bit of a peek if this could somehow be fixed as part of |
Thanks for sharing, yeah I'm not sure of a way to force the rootScope.apply() to occur before any controllers/templates are processed. |
single-spa have custom props feature, but i can't see the way how i could use it in single-spa-angularjs helper to initialize some props on my angularjs app.
Any advice?
The text was updated successfully, but these errors were encountered: