How can I pass object from WEB API CORE 2.0 to Angular 7?
How can I pass object from WEB API CORE 2.0 to Angular 7?
Please give me example.
I got object = null in Angular 7 and don't understand why.
Web Api Controller
[HttpGet]
[Produces("application/json")]
[Route("ListArtists")]
public JsonResult ListArtists()
{
var artists = _context.Artists.ToList();
return Json(new { results = artists });
}
POCO Classes
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; }
}
Angular models
export class Artist {
id: number;
fake: FakeData;
}
export class FakeData {
id: number;
name: string;
}
Getting data in angular using observable
getArtistsList(): Observable<Artist> {
return this.http.get<Artist>(this.myAppUrl + 'api/ArtistsLibrary/ListArtists');
}
component
artists_count: number;
artists: Artist;
ngOnInit() {
this.form = this.fb.group({ searchText: [null, null] });
this.LoadData();
}
LoadData() {
console.log("LoadData");
console.log("checkedList=" + this.checkedList);
const genre_storage = sessionStorage.getItem("genre");
debugger;
this._artistsService
.getArtistsList()
.pipe()
.subscribe((artists: Artist) => {
this.artists = artists;
this.artists_count = artists.length;
});
}

add a comment |
How can I pass object from WEB API CORE 2.0 to Angular 7?
Please give me example.
I got object = null in Angular 7 and don't understand why.
Web Api Controller
[HttpGet]
[Produces("application/json")]
[Route("ListArtists")]
public JsonResult ListArtists()
{
var artists = _context.Artists.ToList();
return Json(new { results = artists });
}
POCO Classes
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; }
}
Angular models
export class Artist {
id: number;
fake: FakeData;
}
export class FakeData {
id: number;
name: string;
}
Getting data in angular using observable
getArtistsList(): Observable<Artist> {
return this.http.get<Artist>(this.myAppUrl + 'api/ArtistsLibrary/ListArtists');
}
component
artists_count: number;
artists: Artist;
ngOnInit() {
this.form = this.fb.group({ searchText: [null, null] });
this.LoadData();
}
LoadData() {
console.log("LoadData");
console.log("checkedList=" + this.checkedList);
const genre_storage = sessionStorage.getItem("genre");
debugger;
this._artistsService
.getArtistsList()
.pipe()
.subscribe((artists: Artist) => {
this.artists = artists;
this.artists_count = artists.length;
});
}

Pls add relevant code here
– User3250
Jan 1 at 10:44
Possible duplicate of Don't see object values from ASP.NET Core MVC in Angular 7 http get
– Tao Zhou
Jan 2 at 3:09
add a comment |
How can I pass object from WEB API CORE 2.0 to Angular 7?
Please give me example.
I got object = null in Angular 7 and don't understand why.
Web Api Controller
[HttpGet]
[Produces("application/json")]
[Route("ListArtists")]
public JsonResult ListArtists()
{
var artists = _context.Artists.ToList();
return Json(new { results = artists });
}
POCO Classes
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; }
}
Angular models
export class Artist {
id: number;
fake: FakeData;
}
export class FakeData {
id: number;
name: string;
}
Getting data in angular using observable
getArtistsList(): Observable<Artist> {
return this.http.get<Artist>(this.myAppUrl + 'api/ArtistsLibrary/ListArtists');
}
component
artists_count: number;
artists: Artist;
ngOnInit() {
this.form = this.fb.group({ searchText: [null, null] });
this.LoadData();
}
LoadData() {
console.log("LoadData");
console.log("checkedList=" + this.checkedList);
const genre_storage = sessionStorage.getItem("genre");
debugger;
this._artistsService
.getArtistsList()
.pipe()
.subscribe((artists: Artist) => {
this.artists = artists;
this.artists_count = artists.length;
});
}

How can I pass object from WEB API CORE 2.0 to Angular 7?
Please give me example.
I got object = null in Angular 7 and don't understand why.
Web Api Controller
[HttpGet]
[Produces("application/json")]
[Route("ListArtists")]
public JsonResult ListArtists()
{
var artists = _context.Artists.ToList();
return Json(new { results = artists });
}
POCO Classes
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; }
}
Angular models
export class Artist {
id: number;
fake: FakeData;
}
export class FakeData {
id: number;
name: string;
}
Getting data in angular using observable
getArtistsList(): Observable<Artist> {
return this.http.get<Artist>(this.myAppUrl + 'api/ArtistsLibrary/ListArtists');
}
component
artists_count: number;
artists: Artist;
ngOnInit() {
this.form = this.fb.group({ searchText: [null, null] });
this.LoadData();
}
LoadData() {
console.log("LoadData");
console.log("checkedList=" + this.checkedList);
const genre_storage = sessionStorage.getItem("genre");
debugger;
this._artistsService
.getArtistsList()
.pipe()
.subscribe((artists: Artist) => {
this.artists = artists;
this.artists_count = artists.length;
});
}


edited Jan 2 at 18:18
t-prisar
7781719
7781719
asked Jan 1 at 10:34
user3161827user3161827
61
61
Pls add relevant code here
– User3250
Jan 1 at 10:44
Possible duplicate of Don't see object values from ASP.NET Core MVC in Angular 7 http get
– Tao Zhou
Jan 2 at 3:09
add a comment |
Pls add relevant code here
– User3250
Jan 1 at 10:44
Possible duplicate of Don't see object values from ASP.NET Core MVC in Angular 7 http get
– Tao Zhou
Jan 2 at 3:09
Pls add relevant code here
– User3250
Jan 1 at 10:44
Pls add relevant code here
– User3250
Jan 1 at 10:44
Possible duplicate of Don't see object values from ASP.NET Core MVC in Angular 7 http get
– Tao Zhou
Jan 2 at 3:09
Possible duplicate of Don't see object values from ASP.NET Core MVC in Angular 7 http get
– Tao Zhou
Jan 2 at 3:09
add a comment |
1 Answer
1
active
oldest
votes
You can create a method in webapi controller to pass the object after serializing into json format.
In angular, you can call that route using angular service to get that json. The json can be mapped into your required javascript object in angular.
This way you are able to pass C# object from asp.net core into javascript object in angular.
[HttpGet]
[Produces("application/json")]
[Route("ListArtists")]
public IActionResult ListArtists()
{
var artists = _context.Artists.ToList();
return Ok(artists);
}
Try checking if the url endpoint is giving you json data. It is a parsing problem.
That's what I did(I attached my code). But got object = null in Angular 7.
– user3161827
Jan 1 at 12:46
I have changed my answer. Try calling the url from browser or postman. If it gives the data check the format it is giving. Since you are putting array ofArtist
,your json result should be enclosed with.
– t-prisar
Jan 1 at 17:31
I tried. IActionResult and JsonResult both correct and I have no problem with webapi.
– user3161827
Jan 1 at 19:44
Postman is correct for both IActionresult snd Jsonresult. Problem that Angular returns object Fakedata = null.
– user3161827
Jan 1 at 19:56
How u subscribed?
– t-prisar
Jan 2 at 4:13
|
show 3 more comments
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%2f53994766%2fhow-can-i-pass-object-from-web-api-core-2-0-to-angular-7%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can create a method in webapi controller to pass the object after serializing into json format.
In angular, you can call that route using angular service to get that json. The json can be mapped into your required javascript object in angular.
This way you are able to pass C# object from asp.net core into javascript object in angular.
[HttpGet]
[Produces("application/json")]
[Route("ListArtists")]
public IActionResult ListArtists()
{
var artists = _context.Artists.ToList();
return Ok(artists);
}
Try checking if the url endpoint is giving you json data. It is a parsing problem.
That's what I did(I attached my code). But got object = null in Angular 7.
– user3161827
Jan 1 at 12:46
I have changed my answer. Try calling the url from browser or postman. If it gives the data check the format it is giving. Since you are putting array ofArtist
,your json result should be enclosed with.
– t-prisar
Jan 1 at 17:31
I tried. IActionResult and JsonResult both correct and I have no problem with webapi.
– user3161827
Jan 1 at 19:44
Postman is correct for both IActionresult snd Jsonresult. Problem that Angular returns object Fakedata = null.
– user3161827
Jan 1 at 19:56
How u subscribed?
– t-prisar
Jan 2 at 4:13
|
show 3 more comments
You can create a method in webapi controller to pass the object after serializing into json format.
In angular, you can call that route using angular service to get that json. The json can be mapped into your required javascript object in angular.
This way you are able to pass C# object from asp.net core into javascript object in angular.
[HttpGet]
[Produces("application/json")]
[Route("ListArtists")]
public IActionResult ListArtists()
{
var artists = _context.Artists.ToList();
return Ok(artists);
}
Try checking if the url endpoint is giving you json data. It is a parsing problem.
That's what I did(I attached my code). But got object = null in Angular 7.
– user3161827
Jan 1 at 12:46
I have changed my answer. Try calling the url from browser or postman. If it gives the data check the format it is giving. Since you are putting array ofArtist
,your json result should be enclosed with.
– t-prisar
Jan 1 at 17:31
I tried. IActionResult and JsonResult both correct and I have no problem with webapi.
– user3161827
Jan 1 at 19:44
Postman is correct for both IActionresult snd Jsonresult. Problem that Angular returns object Fakedata = null.
– user3161827
Jan 1 at 19:56
How u subscribed?
– t-prisar
Jan 2 at 4:13
|
show 3 more comments
You can create a method in webapi controller to pass the object after serializing into json format.
In angular, you can call that route using angular service to get that json. The json can be mapped into your required javascript object in angular.
This way you are able to pass C# object from asp.net core into javascript object in angular.
[HttpGet]
[Produces("application/json")]
[Route("ListArtists")]
public IActionResult ListArtists()
{
var artists = _context.Artists.ToList();
return Ok(artists);
}
Try checking if the url endpoint is giving you json data. It is a parsing problem.
You can create a method in webapi controller to pass the object after serializing into json format.
In angular, you can call that route using angular service to get that json. The json can be mapped into your required javascript object in angular.
This way you are able to pass C# object from asp.net core into javascript object in angular.
[HttpGet]
[Produces("application/json")]
[Route("ListArtists")]
public IActionResult ListArtists()
{
var artists = _context.Artists.ToList();
return Ok(artists);
}
Try checking if the url endpoint is giving you json data. It is a parsing problem.
edited Jan 1 at 17:29
answered Jan 1 at 11:37
t-prisart-prisar
7781719
7781719
That's what I did(I attached my code). But got object = null in Angular 7.
– user3161827
Jan 1 at 12:46
I have changed my answer. Try calling the url from browser or postman. If it gives the data check the format it is giving. Since you are putting array ofArtist
,your json result should be enclosed with.
– t-prisar
Jan 1 at 17:31
I tried. IActionResult and JsonResult both correct and I have no problem with webapi.
– user3161827
Jan 1 at 19:44
Postman is correct for both IActionresult snd Jsonresult. Problem that Angular returns object Fakedata = null.
– user3161827
Jan 1 at 19:56
How u subscribed?
– t-prisar
Jan 2 at 4:13
|
show 3 more comments
That's what I did(I attached my code). But got object = null in Angular 7.
– user3161827
Jan 1 at 12:46
I have changed my answer. Try calling the url from browser or postman. If it gives the data check the format it is giving. Since you are putting array ofArtist
,your json result should be enclosed with.
– t-prisar
Jan 1 at 17:31
I tried. IActionResult and JsonResult both correct and I have no problem with webapi.
– user3161827
Jan 1 at 19:44
Postman is correct for both IActionresult snd Jsonresult. Problem that Angular returns object Fakedata = null.
– user3161827
Jan 1 at 19:56
How u subscribed?
– t-prisar
Jan 2 at 4:13
That's what I did(I attached my code). But got object = null in Angular 7.
– user3161827
Jan 1 at 12:46
That's what I did(I attached my code). But got object = null in Angular 7.
– user3161827
Jan 1 at 12:46
I have changed my answer. Try calling the url from browser or postman. If it gives the data check the format it is giving. Since you are putting array of
Artist
,your json result should be enclosed with
.– t-prisar
Jan 1 at 17:31
I have changed my answer. Try calling the url from browser or postman. If it gives the data check the format it is giving. Since you are putting array of
Artist
,your json result should be enclosed with
.– t-prisar
Jan 1 at 17:31
I tried. IActionResult and JsonResult both correct and I have no problem with webapi.
– user3161827
Jan 1 at 19:44
I tried. IActionResult and JsonResult both correct and I have no problem with webapi.
– user3161827
Jan 1 at 19:44
Postman is correct for both IActionresult snd Jsonresult. Problem that Angular returns object Fakedata = null.
– user3161827
Jan 1 at 19:56
Postman is correct for both IActionresult snd Jsonresult. Problem that Angular returns object Fakedata = null.
– user3161827
Jan 1 at 19:56
How u subscribed?
– t-prisar
Jan 2 at 4:13
How u subscribed?
– t-prisar
Jan 2 at 4:13
|
show 3 more comments
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%2f53994766%2fhow-can-i-pass-object-from-web-api-core-2-0-to-angular-7%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
Pls add relevant code here
– User3250
Jan 1 at 10:44
Possible duplicate of Don't see object values from ASP.NET Core MVC in Angular 7 http get
– Tao Zhou
Jan 2 at 3:09