I want to get the model from my api.
For this I use the method:
[HttpGet]
public MyModel GetModel()
{
MyModel model = new MyModel() { ... };
return model;
}
How can I get the model result in angular and how do I map MyModel
to my angular model?
I have the following:
getModel() {
var url = '/MyController/GetModel/';
this.http.get(url)
.map((data: Response) => {
return data.json() as MyModel;
})
.toPromise().then(x => {
this.myModel = x;
})
}
which I call in ngOnInit
of my component.
But I'm getting an error:
Uncaught (in promise): SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data
What's wrong with my angular request?