export class MockedDataService {
constructor(private Session: SessionService) {}
private getMockedResponse(name:string){
return ""; // placeholder for the response data, will be a promise
}
public mocked:{
products:{
getAllProducts: function(){return this.getMockedResponse("")},
getProductByType: function(type){return this.getMockedResponse(type)}
}
}
}
If you inject this class into a component, you can use it like this:
this.MockedDataService.mocked.products.getAllProducts().then((result) => {
console.log(result);
}).catch((err) => {
console.log("error: ", err.message);
});
An error may occur: "this.getMockedResponse is not a function" To address this issue, modify the code to :
getAllProducts: function(){return ()=> this.getMockedResponse("")}
However, changing it in this way might result in another error: "this.MockedDataService.mocked.products.getAllProducts().then is not a function"