0
下面是一個包含某個http請求的模型。我的問題是我可以通過實例化一個新的類對象實例化服務嗎?angular 2創建自定義變量以在指定的url上執行CRUD
export class DbHttp {
private path:string;
constructor(private path:string, private customService:CustomService){}
create(data:Object):Observable<Response>{
return this.customService.create(this.path, data)
}
getAll():Observable<Response>{
return this.customService.getAll(this.path)
}
}
我想實現的是在自定義url上執行http請求的快捷方式。理想的語法應該是這樣的
public dbAccessTodo = this.service.access('todo')
//access is a method which returns an object with builtin CRUD functions for a Base_Url+'todo'
create(data){
this.dbAccessTodo.create(data)
}
謝謝!