Hi,
I want to minimize the amount of code loaded at runtime, so I want to only
load components as needed. It seems like there should be a simple way to
do this instead of importing a ton of other things which is actually more
code than loading all of the components. Or maybe I'm missing something on
how components are loaded.
Let's say I've made two components in two different files, something like:
@Component({ selector: "dynamic", template: '<p>I am A, it is before
noon</p>' })
export class AComponent{
constructor{ }
}
-----------------------------------
@Component({ selector: "dynamic", template: '<p>I am B, it is after
noon</p>' })
export class BComponent{
constructor{ }
}
My app component might look something like:
@Component({ selector: "app-root", template: '<p>I am the boss</p>
<dynamic></dynamic>' })
export class AppComponent implements OnInit{
constructor{ }
ngOnInit(){ }
}
What I'd like to be able to do is just:
export class AppComponent implements OnInit{
hour = new Date().getHours();
constructor{ }
ngOnInit(){
if(this.hour >=12){
import { AComponent } from './a.component';
}
else{
import { AComponent } from './a.component';
}
}
Fussing through all of the stuff from the tutorial at
https://angular.io/guide/dynamic-component-loader just seems waaaay over
done for something that could literally be done in line at the beginning of
app.component.ts.
Any alternatives?
Thanks!
--
You received this message because you are subscribed to the Google Groups
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.