import { AddReplaceableComponent } from '@abp/ng.core'; // imported AddReplaceableComponent action
import { eIdentityComponents } from '@abp/ng.identity'; // imported eIdentityComponents enum
import { eIdentityComponents } from '@abp/ng.identity'; // imported eIdentityComponents enum
import { Store } from '@ngxs/store'; // imported Store
import { Store } from '@ngxs/store'; // imported Store
//...
//...
@Component(/* component metadata */)
@Component(/* component metadata */)
export class AppComponent implements OnInit {
export class AppComponent {
constructor(..., private store: Store) {} // injected Store
constructor(
private store: Store // injected Store
ngOnInit() {
)
// added dispatch
{
// dispatched the AddReplaceableComponent action
this.store.dispatch(
this.store.dispatch(
new AddReplaceableComponent({
new AddReplaceableComponent({
component: YourNewRoleComponent,
component: YourNewRoleComponent,
key: eIdentityComponents.Roles,
key: eIdentityComponents.Roles,
}),
}),
);
);
//...
}
}
}
}
```
```
@ -60,30 +59,29 @@ Add the following code in your layout template (`my-layout.component.html`) wher
Open `app.component.ts` in `src/app` folder and modify it as shown below:
Open `app.component.ts` in `src/app` folder and modify it as shown below:
```js
```js
import { ..., AddReplaceableComponent } from '@abp/ng.core'; // imported AddReplaceableComponent
import { AddReplaceableComponent } from '@abp/ng.core'; // imported AddReplaceableComponent
import { eThemeBasicComponents } from '@abp/ng.theme.basic'; // imported eThemeBasicComponents enum for component keys
import { eThemeBasicComponents } from '@abp/ng.theme.basic'; // imported eThemeBasicComponents enum for component keys
import { MyApplicationLayoutComponent } from './shared/my-application-layout/my-application-layout.component'; // imported MyApplicationLayoutComponent
import { Store } from '@ngxs/store'; // imported Store
import { Store } from '@ngxs/store'; // imported Store
//...
import { MyApplicationLayoutComponent } from './my-application-layout/my-application-layout.component'; // imported MyApplicationLayoutComponent
@Component(/* component metadata */)
@Component(/* component metadata */)
export class AppComponent implements OnInit {
export class AppComponent {
constructor(..., private store: Store) {} // injected Store
constructor(
private store: Store, // injected Store
ngOnInit() {
) {
// added dispatch
// dispatched the AddReplaceableComponent action
this.store.dispatch(
this.store.dispatch(
new AddReplaceableComponent({
new AddReplaceableComponent({
component: MyApplicationLayoutComponent,
component: MyApplicationLayoutComponent,
key: eThemeBasicComponents.ApplicationLayout,
key: eThemeBasicComponents.ApplicationLayout,
}),
}),
);
);
//...
}
}
}
}
```
```
> If you like to replace a layout component at runtime (e.g: changing the layout by pressing a button), pass the second parameter of the AddReplaceableComponent action as true. DynamicLayoutComponent loads content using a router-outlet. When the second parameter of AddReplaceableComponent is true, the route will be refreshed, so use it with caution. Your component state will be gone and any initiation logic (including HTTP requests) will be repeated.