Angular — Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports...












1















I've created an Angular app with RESTful API authenticated by JWT, and I can access data in general profile page in Angular app, like url: api, but doesn't work for specific page, like url: api/5 which is authenticated by JWT.



However, I found it can access the data set actually, since the correct data was found in error content, so I confused about where went wrong:



enter image description here



my component:



getPosts() {
this._blogPostService.list()
.subscribe(
// the first argument is a function which runs on success
res => {
this.posts = res;
},
// the second argument is a function which runs on error
error => {
console.error('Error saving');
return throwError(error);
},
// the third argument is a function which runs on completion
() => console.log('done loading!'),
);
}


list() here:



list() { 
return this.http.get('api/1', {
headers:{
'Content-Type': 'application/json',
Authorization: 'JWT ' + this._userService.token
}
});
}


my html:



<button (click)="getPosts()">get quote</button>
<br><br>
<h2 class="mt-3">Student Profile Pages</h2>
<li *ngFor="let each of posts">

<label class="col-md-2">Student:</label>
<div class="col-md-2 mb-1">{{ each.user.username }}</div>

<div class="col-md-2">{{ each.user.email }}</div>
<div class="col-md-2">{{ each.location }}</div>
<div class="col-md-2">{{ each.about }}</div>

</li>


my dataset is that:



{
"url": "http://127.0.0.1:8000/users/studentprofiles/5/",
"id": 5,
"user": {
"url": "http://127.0.0.1:8000/users/users/7/",
"id": 7,
"username": "student",
"password": "pbkdf2_sha256$120000$RGxW5X7OSwOw$hTU34GiyexDV4aT6hNQy0rHsWllnLdAm9vSohBvUqi4=",
"first_name": "Hongzhi",
"last_name": "Zhang",
"email": "hongzhiz1@student.unimelb.edu.au",
"user_type": 1,
"is_superuser": false,
"is_staff": false
},
"location": "richmond",
"about": "this is a test",
"phone": 3214324,
"birthday": "1992-08-18",
"owned_skills": [
"http://127.0.0.1:8000/users/skills/3/"
],
"chosen_interests": [
"http://127.0.0.1:8000/users/interests/1/",
"http://127.0.0.1:8000/users/interests/2/"
],
"date_created": "2018-11-05T04:47:23.461476Z",
"date_updated": "2018-11-15T05:07:17.456501Z",
}


I really want to know where went wrong.



I also referred to the answers in some similar questions, like: https://stackoverflow.com/a/49084550/6932409, but it doesn't work on my app.










share|improve this question

























  • BTW, my angular version is Angular CLI: 7.0.6

    – hsbzzhz
    Nov 23 '18 at 3:45






  • 1





    This is definitely not angularjs(1.x), it is clearly angular(2.x+). These are not the same framework, and do not operate in the same manner.

    – Claies
    Nov 23 '18 at 3:47











  • also, attempts to edit the question show that there is a question with the exact same title, stackoverflow.com/questions/39819392/…. Is that question relevant to your problem?

    – Claies
    Nov 23 '18 at 3:49













  • Are you receiving an error? If so please provide the details. If not put a breakpoint on this.posts = res and see what is happening.

    – Dale Burrell
    Nov 23 '18 at 3:49






  • 1





    There is your issue then :) google that and you'll be sorted.

    – Dale Burrell
    Nov 23 '18 at 4:49
















1















I've created an Angular app with RESTful API authenticated by JWT, and I can access data in general profile page in Angular app, like url: api, but doesn't work for specific page, like url: api/5 which is authenticated by JWT.



However, I found it can access the data set actually, since the correct data was found in error content, so I confused about where went wrong:



enter image description here



my component:



getPosts() {
this._blogPostService.list()
.subscribe(
// the first argument is a function which runs on success
res => {
this.posts = res;
},
// the second argument is a function which runs on error
error => {
console.error('Error saving');
return throwError(error);
},
// the third argument is a function which runs on completion
() => console.log('done loading!'),
);
}


list() here:



list() { 
return this.http.get('api/1', {
headers:{
'Content-Type': 'application/json',
Authorization: 'JWT ' + this._userService.token
}
});
}


my html:



<button (click)="getPosts()">get quote</button>
<br><br>
<h2 class="mt-3">Student Profile Pages</h2>
<li *ngFor="let each of posts">

<label class="col-md-2">Student:</label>
<div class="col-md-2 mb-1">{{ each.user.username }}</div>

<div class="col-md-2">{{ each.user.email }}</div>
<div class="col-md-2">{{ each.location }}</div>
<div class="col-md-2">{{ each.about }}</div>

</li>


my dataset is that:



{
"url": "http://127.0.0.1:8000/users/studentprofiles/5/",
"id": 5,
"user": {
"url": "http://127.0.0.1:8000/users/users/7/",
"id": 7,
"username": "student",
"password": "pbkdf2_sha256$120000$RGxW5X7OSwOw$hTU34GiyexDV4aT6hNQy0rHsWllnLdAm9vSohBvUqi4=",
"first_name": "Hongzhi",
"last_name": "Zhang",
"email": "hongzhiz1@student.unimelb.edu.au",
"user_type": 1,
"is_superuser": false,
"is_staff": false
},
"location": "richmond",
"about": "this is a test",
"phone": 3214324,
"birthday": "1992-08-18",
"owned_skills": [
"http://127.0.0.1:8000/users/skills/3/"
],
"chosen_interests": [
"http://127.0.0.1:8000/users/interests/1/",
"http://127.0.0.1:8000/users/interests/2/"
],
"date_created": "2018-11-05T04:47:23.461476Z",
"date_updated": "2018-11-15T05:07:17.456501Z",
}


I really want to know where went wrong.



I also referred to the answers in some similar questions, like: https://stackoverflow.com/a/49084550/6932409, but it doesn't work on my app.










share|improve this question

























  • BTW, my angular version is Angular CLI: 7.0.6

    – hsbzzhz
    Nov 23 '18 at 3:45






  • 1





    This is definitely not angularjs(1.x), it is clearly angular(2.x+). These are not the same framework, and do not operate in the same manner.

    – Claies
    Nov 23 '18 at 3:47











  • also, attempts to edit the question show that there is a question with the exact same title, stackoverflow.com/questions/39819392/…. Is that question relevant to your problem?

    – Claies
    Nov 23 '18 at 3:49













  • Are you receiving an error? If so please provide the details. If not put a breakpoint on this.posts = res and see what is happening.

    – Dale Burrell
    Nov 23 '18 at 3:49






  • 1





    There is your issue then :) google that and you'll be sorted.

    – Dale Burrell
    Nov 23 '18 at 4:49














1












1








1








I've created an Angular app with RESTful API authenticated by JWT, and I can access data in general profile page in Angular app, like url: api, but doesn't work for specific page, like url: api/5 which is authenticated by JWT.



However, I found it can access the data set actually, since the correct data was found in error content, so I confused about where went wrong:



enter image description here



my component:



getPosts() {
this._blogPostService.list()
.subscribe(
// the first argument is a function which runs on success
res => {
this.posts = res;
},
// the second argument is a function which runs on error
error => {
console.error('Error saving');
return throwError(error);
},
// the third argument is a function which runs on completion
() => console.log('done loading!'),
);
}


list() here:



list() { 
return this.http.get('api/1', {
headers:{
'Content-Type': 'application/json',
Authorization: 'JWT ' + this._userService.token
}
});
}


my html:



<button (click)="getPosts()">get quote</button>
<br><br>
<h2 class="mt-3">Student Profile Pages</h2>
<li *ngFor="let each of posts">

<label class="col-md-2">Student:</label>
<div class="col-md-2 mb-1">{{ each.user.username }}</div>

<div class="col-md-2">{{ each.user.email }}</div>
<div class="col-md-2">{{ each.location }}</div>
<div class="col-md-2">{{ each.about }}</div>

</li>


my dataset is that:



{
"url": "http://127.0.0.1:8000/users/studentprofiles/5/",
"id": 5,
"user": {
"url": "http://127.0.0.1:8000/users/users/7/",
"id": 7,
"username": "student",
"password": "pbkdf2_sha256$120000$RGxW5X7OSwOw$hTU34GiyexDV4aT6hNQy0rHsWllnLdAm9vSohBvUqi4=",
"first_name": "Hongzhi",
"last_name": "Zhang",
"email": "hongzhiz1@student.unimelb.edu.au",
"user_type": 1,
"is_superuser": false,
"is_staff": false
},
"location": "richmond",
"about": "this is a test",
"phone": 3214324,
"birthday": "1992-08-18",
"owned_skills": [
"http://127.0.0.1:8000/users/skills/3/"
],
"chosen_interests": [
"http://127.0.0.1:8000/users/interests/1/",
"http://127.0.0.1:8000/users/interests/2/"
],
"date_created": "2018-11-05T04:47:23.461476Z",
"date_updated": "2018-11-15T05:07:17.456501Z",
}


I really want to know where went wrong.



I also referred to the answers in some similar questions, like: https://stackoverflow.com/a/49084550/6932409, but it doesn't work on my app.










share|improve this question
















I've created an Angular app with RESTful API authenticated by JWT, and I can access data in general profile page in Angular app, like url: api, but doesn't work for specific page, like url: api/5 which is authenticated by JWT.



However, I found it can access the data set actually, since the correct data was found in error content, so I confused about where went wrong:



enter image description here



my component:



getPosts() {
this._blogPostService.list()
.subscribe(
// the first argument is a function which runs on success
res => {
this.posts = res;
},
// the second argument is a function which runs on error
error => {
console.error('Error saving');
return throwError(error);
},
// the third argument is a function which runs on completion
() => console.log('done loading!'),
);
}


list() here:



list() { 
return this.http.get('api/1', {
headers:{
'Content-Type': 'application/json',
Authorization: 'JWT ' + this._userService.token
}
});
}


my html:



<button (click)="getPosts()">get quote</button>
<br><br>
<h2 class="mt-3">Student Profile Pages</h2>
<li *ngFor="let each of posts">

<label class="col-md-2">Student:</label>
<div class="col-md-2 mb-1">{{ each.user.username }}</div>

<div class="col-md-2">{{ each.user.email }}</div>
<div class="col-md-2">{{ each.location }}</div>
<div class="col-md-2">{{ each.about }}</div>

</li>


my dataset is that:



{
"url": "http://127.0.0.1:8000/users/studentprofiles/5/",
"id": 5,
"user": {
"url": "http://127.0.0.1:8000/users/users/7/",
"id": 7,
"username": "student",
"password": "pbkdf2_sha256$120000$RGxW5X7OSwOw$hTU34GiyexDV4aT6hNQy0rHsWllnLdAm9vSohBvUqi4=",
"first_name": "Hongzhi",
"last_name": "Zhang",
"email": "hongzhiz1@student.unimelb.edu.au",
"user_type": 1,
"is_superuser": false,
"is_staff": false
},
"location": "richmond",
"about": "this is a test",
"phone": 3214324,
"birthday": "1992-08-18",
"owned_skills": [
"http://127.0.0.1:8000/users/skills/3/"
],
"chosen_interests": [
"http://127.0.0.1:8000/users/interests/1/",
"http://127.0.0.1:8000/users/interests/2/"
],
"date_created": "2018-11-05T04:47:23.461476Z",
"date_updated": "2018-11-15T05:07:17.456501Z",
}


I really want to know where went wrong.



I also referred to the answers in some similar questions, like: https://stackoverflow.com/a/49084550/6932409, but it doesn't work on my app.







angular django-rest-framework jwt






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 4:18









georgeawg

33.1k104968




33.1k104968










asked Nov 23 '18 at 3:40









hsbzzhzhsbzzhz

367




367













  • BTW, my angular version is Angular CLI: 7.0.6

    – hsbzzhz
    Nov 23 '18 at 3:45






  • 1





    This is definitely not angularjs(1.x), it is clearly angular(2.x+). These are not the same framework, and do not operate in the same manner.

    – Claies
    Nov 23 '18 at 3:47











  • also, attempts to edit the question show that there is a question with the exact same title, stackoverflow.com/questions/39819392/…. Is that question relevant to your problem?

    – Claies
    Nov 23 '18 at 3:49













  • Are you receiving an error? If so please provide the details. If not put a breakpoint on this.posts = res and see what is happening.

    – Dale Burrell
    Nov 23 '18 at 3:49






  • 1





    There is your issue then :) google that and you'll be sorted.

    – Dale Burrell
    Nov 23 '18 at 4:49



















  • BTW, my angular version is Angular CLI: 7.0.6

    – hsbzzhz
    Nov 23 '18 at 3:45






  • 1





    This is definitely not angularjs(1.x), it is clearly angular(2.x+). These are not the same framework, and do not operate in the same manner.

    – Claies
    Nov 23 '18 at 3:47











  • also, attempts to edit the question show that there is a question with the exact same title, stackoverflow.com/questions/39819392/…. Is that question relevant to your problem?

    – Claies
    Nov 23 '18 at 3:49













  • Are you receiving an error? If so please provide the details. If not put a breakpoint on this.posts = res and see what is happening.

    – Dale Burrell
    Nov 23 '18 at 3:49






  • 1





    There is your issue then :) google that and you'll be sorted.

    – Dale Burrell
    Nov 23 '18 at 4:49

















BTW, my angular version is Angular CLI: 7.0.6

– hsbzzhz
Nov 23 '18 at 3:45





BTW, my angular version is Angular CLI: 7.0.6

– hsbzzhz
Nov 23 '18 at 3:45




1




1





This is definitely not angularjs(1.x), it is clearly angular(2.x+). These are not the same framework, and do not operate in the same manner.

– Claies
Nov 23 '18 at 3:47





This is definitely not angularjs(1.x), it is clearly angular(2.x+). These are not the same framework, and do not operate in the same manner.

– Claies
Nov 23 '18 at 3:47













also, attempts to edit the question show that there is a question with the exact same title, stackoverflow.com/questions/39819392/…. Is that question relevant to your problem?

– Claies
Nov 23 '18 at 3:49







also, attempts to edit the question show that there is a question with the exact same title, stackoverflow.com/questions/39819392/…. Is that question relevant to your problem?

– Claies
Nov 23 '18 at 3:49















Are you receiving an error? If so please provide the details. If not put a breakpoint on this.posts = res and see what is happening.

– Dale Burrell
Nov 23 '18 at 3:49





Are you receiving an error? If so please provide the details. If not put a breakpoint on this.posts = res and see what is happening.

– Dale Burrell
Nov 23 '18 at 3:49




1




1





There is your issue then :) google that and you'll be sorted.

– Dale Burrell
Nov 23 '18 at 4:49





There is your issue then :) google that and you'll be sorted.

– Dale Burrell
Nov 23 '18 at 4:49












1 Answer
1






active

oldest

votes


















0














The problem is about CORS, there are two approaches to solve this problem, one is add 'Access-Control-Allow-Origin': '*' to your http request, sometimes you need add more. Another answer is add CORS_ORIGIN_WHITELIST = 'localhost:4200', in your backend.






share|improve this answer























    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
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53440399%2fangular-cannot-find-a-differ-supporting-object-object-object-of-type-obj%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









    0














    The problem is about CORS, there are two approaches to solve this problem, one is add 'Access-Control-Allow-Origin': '*' to your http request, sometimes you need add more. Another answer is add CORS_ORIGIN_WHITELIST = 'localhost:4200', in your backend.






    share|improve this answer




























      0














      The problem is about CORS, there are two approaches to solve this problem, one is add 'Access-Control-Allow-Origin': '*' to your http request, sometimes you need add more. Another answer is add CORS_ORIGIN_WHITELIST = 'localhost:4200', in your backend.






      share|improve this answer


























        0












        0








        0







        The problem is about CORS, there are two approaches to solve this problem, one is add 'Access-Control-Allow-Origin': '*' to your http request, sometimes you need add more. Another answer is add CORS_ORIGIN_WHITELIST = 'localhost:4200', in your backend.






        share|improve this answer













        The problem is about CORS, there are two approaches to solve this problem, one is add 'Access-Control-Allow-Origin': '*' to your http request, sometimes you need add more. Another answer is add CORS_ORIGIN_WHITELIST = 'localhost:4200', in your backend.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 26 '18 at 0:37









        hsbzzhzhsbzzhz

        367




        367






























            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53440399%2fangular-cannot-find-a-differ-supporting-object-object-object-of-type-obj%23new-answer', 'question_page');
            }
            );

            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







            Popular posts from this blog

            To store a contact into the json file from server.js file using a class in NodeJS

            Redirect URL with Chrome Remote Debugging Android Devices

            Dieringhausen