Don't see object values from ASP.NET Core MVC in Angular 7 http get
I developed an ASP.NET Core 2.0 Web API service and try to use HttpGet
method: http://localhost:50223/api/ArtistsLibrary/ListArtists
[HttpGet]
[Produces("application/json")]
[Route("ListArtists")]
public JsonResult ListArtists()
{
var artists = _context.Artists.ToList();
return Json(new { results = artists });
}
public class Artist
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int id { get; set; }
public FakeData fake { get; set; }
}
public class FakeData
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int id { get; set; }
public string name { get; set; }
}
It returns:
{
"results": [
{
"id": 1,
"fake": {
"id": 1,
"name": "m1"
}
},
{
"id": 2,
"fake": {
"id": 2,
"name": "m2"
}
}
]
}
Everything is OK, but when I try to get the data from Angular 7, I got "fake = null":
getArtistsList(): Observable<Artist> {
return this.http.get<Artist>(this.myAppUrl +
'api/ArtistsLibrary/ListArtists'); }
LoadData() {
this._artistsService.getArtistsList().subscribe((d) => {
debugger;
this.artists = d;
console.log(this.artists);
});
}
Results:
Array(2) 0: fake: null id: 1
1: fake: null id: 2
Please help me.
angular asp.net-core-webapi
|
show 6 more comments
I developed an ASP.NET Core 2.0 Web API service and try to use HttpGet
method: http://localhost:50223/api/ArtistsLibrary/ListArtists
[HttpGet]
[Produces("application/json")]
[Route("ListArtists")]
public JsonResult ListArtists()
{
var artists = _context.Artists.ToList();
return Json(new { results = artists });
}
public class Artist
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int id { get; set; }
public FakeData fake { get; set; }
}
public class FakeData
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int id { get; set; }
public string name { get; set; }
}
It returns:
{
"results": [
{
"id": 1,
"fake": {
"id": 1,
"name": "m1"
}
},
{
"id": 2,
"fake": {
"id": 2,
"name": "m2"
}
}
]
}
Everything is OK, but when I try to get the data from Angular 7, I got "fake = null":
getArtistsList(): Observable<Artist> {
return this.http.get<Artist>(this.myAppUrl +
'api/ArtistsLibrary/ListArtists'); }
LoadData() {
this._artistsService.getArtistsList().subscribe((d) => {
debugger;
this.artists = d;
console.log(this.artists);
});
}
Results:
Array(2) 0: fake: null id: 1
1: fake: null id: 2
Please help me.
angular asp.net-core-webapi
3
Welcome to stack overflow! What does your Artist interface look like in your Angular app?
– DeborahK
Dec 28 '18 at 19:41
1
Did you test localhost:50223/api/ArtistsLibrary/ListArtists on Postman or your browser to make sure it gives the expected results?
– Mitch Wilkins
Dec 28 '18 at 22:19
Yes,I checked on Postman and gave expected results. Problem only in get of Angular 7 with object FakeData.
– user3161827
Dec 29 '18 at 11:00
The same problem if I add to Artist class member public List<Song> all_songs { get; set; }.Then I get in http service in Angular all_songs = null (http get).
– user3161827
Dec 29 '18 at 11:56
export class ArtistsService { myAppUrl = 'localhost:50223'; constructor(private http: HttpClient) { } getArtistsList(): Observable<Artist> { return this.http.get<Artist>(this.myAppUrl + 'api/ArtistsLibrary/ListArtists'); } }
– user3161827
Dec 29 '18 at 11:58
|
show 6 more comments
I developed an ASP.NET Core 2.0 Web API service and try to use HttpGet
method: http://localhost:50223/api/ArtistsLibrary/ListArtists
[HttpGet]
[Produces("application/json")]
[Route("ListArtists")]
public JsonResult ListArtists()
{
var artists = _context.Artists.ToList();
return Json(new { results = artists });
}
public class Artist
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int id { get; set; }
public FakeData fake { get; set; }
}
public class FakeData
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int id { get; set; }
public string name { get; set; }
}
It returns:
{
"results": [
{
"id": 1,
"fake": {
"id": 1,
"name": "m1"
}
},
{
"id": 2,
"fake": {
"id": 2,
"name": "m2"
}
}
]
}
Everything is OK, but when I try to get the data from Angular 7, I got "fake = null":
getArtistsList(): Observable<Artist> {
return this.http.get<Artist>(this.myAppUrl +
'api/ArtistsLibrary/ListArtists'); }
LoadData() {
this._artistsService.getArtistsList().subscribe((d) => {
debugger;
this.artists = d;
console.log(this.artists);
});
}
Results:
Array(2) 0: fake: null id: 1
1: fake: null id: 2
Please help me.
angular asp.net-core-webapi
I developed an ASP.NET Core 2.0 Web API service and try to use HttpGet
method: http://localhost:50223/api/ArtistsLibrary/ListArtists
[HttpGet]
[Produces("application/json")]
[Route("ListArtists")]
public JsonResult ListArtists()
{
var artists = _context.Artists.ToList();
return Json(new { results = artists });
}
public class Artist
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int id { get; set; }
public FakeData fake { get; set; }
}
public class FakeData
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int id { get; set; }
public string name { get; set; }
}
It returns:
{
"results": [
{
"id": 1,
"fake": {
"id": 1,
"name": "m1"
}
},
{
"id": 2,
"fake": {
"id": 2,
"name": "m2"
}
}
]
}
Everything is OK, but when I try to get the data from Angular 7, I got "fake = null":
getArtistsList(): Observable<Artist> {
return this.http.get<Artist>(this.myAppUrl +
'api/ArtistsLibrary/ListArtists'); }
LoadData() {
this._artistsService.getArtistsList().subscribe((d) => {
debugger;
this.artists = d;
console.log(this.artists);
});
}
Results:
Array(2) 0: fake: null id: 1
1: fake: null id: 2
Please help me.
angular asp.net-core-webapi
angular asp.net-core-webapi
edited Dec 28 '18 at 20:09
marc_s
572k12811071253
572k12811071253
asked Dec 28 '18 at 18:06
user3161827user3161827
61
61
3
Welcome to stack overflow! What does your Artist interface look like in your Angular app?
– DeborahK
Dec 28 '18 at 19:41
1
Did you test localhost:50223/api/ArtistsLibrary/ListArtists on Postman or your browser to make sure it gives the expected results?
– Mitch Wilkins
Dec 28 '18 at 22:19
Yes,I checked on Postman and gave expected results. Problem only in get of Angular 7 with object FakeData.
– user3161827
Dec 29 '18 at 11:00
The same problem if I add to Artist class member public List<Song> all_songs { get; set; }.Then I get in http service in Angular all_songs = null (http get).
– user3161827
Dec 29 '18 at 11:56
export class ArtistsService { myAppUrl = 'localhost:50223'; constructor(private http: HttpClient) { } getArtistsList(): Observable<Artist> { return this.http.get<Artist>(this.myAppUrl + 'api/ArtistsLibrary/ListArtists'); } }
– user3161827
Dec 29 '18 at 11:58
|
show 6 more comments
3
Welcome to stack overflow! What does your Artist interface look like in your Angular app?
– DeborahK
Dec 28 '18 at 19:41
1
Did you test localhost:50223/api/ArtistsLibrary/ListArtists on Postman or your browser to make sure it gives the expected results?
– Mitch Wilkins
Dec 28 '18 at 22:19
Yes,I checked on Postman and gave expected results. Problem only in get of Angular 7 with object FakeData.
– user3161827
Dec 29 '18 at 11:00
The same problem if I add to Artist class member public List<Song> all_songs { get; set; }.Then I get in http service in Angular all_songs = null (http get).
– user3161827
Dec 29 '18 at 11:56
export class ArtistsService { myAppUrl = 'localhost:50223'; constructor(private http: HttpClient) { } getArtistsList(): Observable<Artist> { return this.http.get<Artist>(this.myAppUrl + 'api/ArtistsLibrary/ListArtists'); } }
– user3161827
Dec 29 '18 at 11:58
3
3
Welcome to stack overflow! What does your Artist interface look like in your Angular app?
– DeborahK
Dec 28 '18 at 19:41
Welcome to stack overflow! What does your Artist interface look like in your Angular app?
– DeborahK
Dec 28 '18 at 19:41
1
1
Did you test localhost:50223/api/ArtistsLibrary/ListArtists on Postman or your browser to make sure it gives the expected results?
– Mitch Wilkins
Dec 28 '18 at 22:19
Did you test localhost:50223/api/ArtistsLibrary/ListArtists on Postman or your browser to make sure it gives the expected results?
– Mitch Wilkins
Dec 28 '18 at 22:19
Yes,I checked on Postman and gave expected results. Problem only in get of Angular 7 with object FakeData.
– user3161827
Dec 29 '18 at 11:00
Yes,I checked on Postman and gave expected results. Problem only in get of Angular 7 with object FakeData.
– user3161827
Dec 29 '18 at 11:00
The same problem if I add to Artist class member public List<Song> all_songs { get; set; }.Then I get in http service in Angular all_songs = null (http get).
– user3161827
Dec 29 '18 at 11:56
The same problem if I add to Artist class member public List<Song> all_songs { get; set; }.Then I get in http service in Angular all_songs = null (http get).
– user3161827
Dec 29 '18 at 11:56
export class ArtistsService { myAppUrl = 'localhost:50223'; constructor(private http: HttpClient) { } getArtistsList(): Observable<Artist> { return this.http.get<Artist>(this.myAppUrl + 'api/ArtistsLibrary/ListArtists'); } }
– user3161827
Dec 29 '18 at 11:58
export class ArtistsService { myAppUrl = 'localhost:50223'; constructor(private http: HttpClient) { } getArtistsList(): Observable<Artist> { return this.http.get<Artist>(this.myAppUrl + 'api/ArtistsLibrary/ListArtists'); } }
– user3161827
Dec 29 '18 at 11:58
|
show 6 more comments
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53962597%2fdont-see-object-values-from-asp-net-core-mvc-in-angular-7-http-get%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53962597%2fdont-see-object-values-from-asp-net-core-mvc-in-angular-7-http-get%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
Welcome to stack overflow! What does your Artist interface look like in your Angular app?
– DeborahK
Dec 28 '18 at 19:41
1
Did you test localhost:50223/api/ArtistsLibrary/ListArtists on Postman or your browser to make sure it gives the expected results?
– Mitch Wilkins
Dec 28 '18 at 22:19
Yes,I checked on Postman and gave expected results. Problem only in get of Angular 7 with object FakeData.
– user3161827
Dec 29 '18 at 11:00
The same problem if I add to Artist class member public List<Song> all_songs { get; set; }.Then I get in http service in Angular all_songs = null (http get).
– user3161827
Dec 29 '18 at 11:56
export class ArtistsService { myAppUrl = 'localhost:50223'; constructor(private http: HttpClient) { } getArtistsList(): Observable<Artist> { return this.http.get<Artist>(this.myAppUrl + 'api/ArtistsLibrary/ListArtists'); } }
– user3161827
Dec 29 '18 at 11:58