0
class SimpleComponent {

}


var string = 'SimpleComponent';

bootstrapComponents.push(string); // This should be 'SimpleComponent' class and not a string value.

How can I pass class object from a string value in typescript?

5
  • Can you please explain what you are trying to achieve? Perhaps there is a better way to implement this. Commented Nov 12, 2016 at 20:08
  • Where did you use object? Commented Nov 12, 2016 at 20:46
  • @RomanC I'm using object in angular bootstrap method... so it will bootstrap thous objects and I'm passing dynamic values in array, which will load thous component, which then will be bootstrap. Commented Nov 12, 2016 at 21:46
  • @NateMay added description on previous comment Commented Nov 12, 2016 at 21:48
  • @Basit yes, this sounds like the angular modular import export system. Angular will only load modules that a required, i.e. the router directs to the component. This was by design and abstracts away the need to manage component bootstrapping. Commented Nov 12, 2016 at 23:52

2 Answers 2

1

add the class name as a key

var classPointer={'SimpleComponent':SimpleComponent};

 bootstrapComponents.push(classPointer[string]);
Sign up to request clarification or add additional context in comments.

Comments

0

As far as I know, the modular concept of angular2 isn't to store classes in arrays or objects and push them around, it is to export classes and import them elsewhere. In stead, segment you application into modules and load them via the router. Unused modules and their respective components will only load once they are needed, unless otherwise specified via lazyload.

1 Comment

1. router is giving issues currently with non-spa app, 2. my solution would load more then one component and freely without in app-root (works better for non-spa).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.