Basit Basit - 1 year ago 77
Javascript Question

typescript + angular2 pass class from a string value

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?

Answer Source

add the class name as a key

var classPointer={'SimpleComponent':SimpleComponent};

 bootstrapComponents.push(classPointer[string]);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download