Basit Basit - 25 days ago 6
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

add the class name as a key

var classPointer={'SimpleComponent':SimpleComponent};

 bootstrapComponents.push(classPointer[string]);