-
Notifications
You must be signed in to change notification settings - Fork 47
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
UserBox Layout Customization #57
Comments
Here's the hack. I only want the UserBox' HTML template to be <div class='user-body'>
{{ currentUser.email }}
</div> To achieve this, I had to go really deep into Angular internals. First, you have to add a very invasive piece of code to Second, you have to provide a customised DirectiveResolver, which when loading all components, modifies the HTML template of the component, whose selector is
import { enableProdMode } from '@angular/core';
import { DirectiveResolver, CompileReflector } from '@angular/compiler';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
import { CustomDirectiveResolver } from './custom-directive.resolver';
if (environment.production) {
enableProdMode();
}
platformBrowserDynamic().bootstrapModule(
AppModule, {
providers: [
{
provide: DirectiveResolver,
useClass: CustomDirectiveResolver,
deps: [
CompileReflector
]
},
]
})
.then(ref => {
// Ensure Angular destroys itself on hot reloads.
if (window['ngRef']) {
window['ngRef'].destroy();
}
window['ngRef'] = ref;
// Otherise, log the boot error
})
.catch(err => console.error(err)); Finally This is its content for my purposes: import { Directive, Type, Component } from '@angular/core';
import { DirectiveResolver } from '@angular/compiler';
// import { environment } from '../environments/environment';
export class CustomDirectiveResolver extends DirectiveResolver {
resolve (type: Type<any>, throwIfNotFound?: boolean): Directive {
const view: Component = super.resolve(type, throwIfNotFound);
if (!view) {
return view;
}
// use this to inspect all components, it is quite interesting
// console.log(JSON.stringify(view));
if (view.selector === '.userBox') {
view.template = `
<div class='user-body'>
{{ currentUser.email }}
</div>
`;
view.templateUrl = null;
}
return view;
}
} I wish there was a much simpler way. |
A very clever solution, thank you to have shared.
@TwanoO67 it's better a structural change to |
This would be the proper way.
<ng-content></ng-content>
The fundamental problem with A. It wants to be an Angular Library for AminLTE, offering natural Angular Components, Services, Pipes etc. B. It also wants to showcase AdminLTE, so as the beginner developer gets something up quickly. C. It does want to keep compatibility to very old APIs, such as before Angular 4. It is high time the list gets reconsidered. My plan is to concentrate on A and defining a lower boundary for Angular, addressing C. B is best addressed in a separate project, say |
I totally agree! Hard coded string shouldn't be in here (or at least in the translation files), and all parts of the app should be customisable.
I would rather set a service for that, in the same way that menu, or control-sidebar works I also agree with @catull, ngx-admin-lte have to stick to purpose A. I also agree with stopping backward compatibility to Angular4 level for this package version >2 |
@TwanoO67 Then please, in the README.md state that this project is for "Angular 4+", drop " |
It needs to allow the customization of userBox.
Before to work to this issue, has someone done something about?
Here @catull spoke about a hack...
The text was updated successfully, but these errors were encountered: