Use one main class has all classes that I need in my components. Is that bad way?

M

Mazin

Guest
I have question about building projects in Angular 7.

I have a many of duplicate classes that used in every component. I thought I make one class has all of classes that I need , instead of importing all these classes in every component.

This will make me controlling on the project easily. But I don't know if this bad way or good way? is It consumes a lot memory and resources or no?

EX My main class "AppImports" :

import { Injectable } from '@angular/core';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';
import 'rxjs/add/operator/map';
import {Router , ActivatedRoute} from "@angular/router"
import { Platform,MenuController, ModalController , AlertController, ToastController, PopoverController, ActionSheetController , NavController } from '@ionic/angular';
import { Keyboard } from '@ionic-native/keyboard/ngx';
import { Language } from './language';
import { Display } from './display';
import { Api } from './api';
import { Buttons } from './buttons';
import { Animations } from './animations';

@Injectable()
export class AppImports {

constructor(
public platform: Platform,
public splashScreen: SplashScreen,
public statusBar: StatusBar,
public keyboard: Keyboard,
public router: Router,
public activRoute: ActivatedRoute,
public menu: MenuController,
public modals: ModalController,
public alerts: AlertController,
public toasts:ToastController,
public pops: PopoverController,
public sheets: ActionSheetController ,
public navs: NavController,
public lang: Language,
public display: Display,
public api: Api,
public button: Buttons,
public animation: Animations
){}




}


In my component I imported only one class "AppImports" that has all of my classes:

import { Component } from '@angular/core';
import { AppImports } from '../imports/app-imports'



@Component({
selector: 'app-root',
templateUrl: 'app.component.html',
styleUrls: ['app.component.scss'],

})
export class AppComponent {

constructor(
public app :AppImports,
) {


this.app.menu.open();

}



}



so, Is it bad way or good way?

Continue reading...
 
Top