Creating ActonSheetController Object at RunTime

I am new to Ionic and Angular 2/4. So be patient with me :slight_smile:

According to documentation, if I have to use ActionSheetController, I am suppose to pass it in constructor like this.

constructor(public actionSheetCtrl: ActionSheetController) { }

And later use it like this.

let actionSheet = this.actionSheetCtrl.create({})
actionSheet.present()

But what if I want to make it when I want it without passing it in the constructor? I believe I have to create an object like this.

let actionSheet = new ActionSheetController(_app: App, config: Config)

But I am not sure what to pass in as app and config attribute.

Thanks.

You don’t. Always let Angular’s DI manage the lifecycle of components and services.

1 Like

Only use code like this for meta-programming. For example, if you’re in Java and you need to use reflection. Basically, unless you’re writing an Angular compiler or something with that “I can see myself” flavor, it’s best to leave this alone. Why? Because the main performance advantage of Angular over Javascript is ahead-of-time compiling. So you want to present everything you can exactly the way the framework expects so it can optimize for you. And for most programs, on most devices, time is much more important than space for user experience. So don’t sweat it if the framework uses some “extra” memory for your page (unless it’s huge or a leak). Focus on getting your pages to render as fast as possible. My two cents.