var someObject = {
func: (http: Http)=>{
// do something
}
}
---------------------------------------------
// somewhere in an ng2 module
function injectServices(theObject){
let services = getServices(theObject.func)
//inject services into theObject
....
}
// return services
function getServices(func: Function){
// get params' type of func
let paramTypes = ...
// get services' singleton
let singletons = ...
return singletons;
}
Does Reflect provides such method so that I can get params' type of a function? How could I get the service classes' singleton?
The scenario is I will take an object which implements the interface below to render a form view and I have some custom services that should be injected into $validator, $parser, and $formatter at runtime.
interface IViewSchema {
"title": String,
"buttons": [
{
"buttonText": String,
"role?": "cancel" | "submit",
"callback?": 'cancel' | 'submit' | Function,
"disabled": String
}
],
"viewTemplate?": String,
"formControls?": [
{
"formTemplate?": String,
"label": String,
"maxLength?": number, // max length of input
"minLength?": number, // min length of input
"hidden?": String, // if hidden is true, hide the form control
"disabled?": String, // if data is editable or not, default true,
"placeholder?": String,
"model?": String,
"$validate?":Function[],
"$parser?": { // parse modal data to view data
"async?": boolean, // default false, run async parser or not
"remote?": { // enabled only when async is true
"url": String, // remote url
"method?": String, // calling method
"headers?": JSON,
"body?": String | JSON
},
"parse?": Function
},
"$formatter?": Function
}
]
}