1

I can't able to render my html grid table in angular using json data that is from mysql database.Please someone help me.

Output of the angular code

    export class UserlistComponent implements OnInit {

  users: Observable<User[]>;

  constructor(private _service:NgserviceService, private _route:Router) { }

  ngOnInit() {
    this.reloadData();
  }

  reloadData(){
    this.users = this._service.getUserList();
  }
}
9
  • Please atach part of your code Commented Aug 31, 2020 at 7:13
  • It seems you have there array of arrays, not array of object therefore let user is array not object Commented Aug 31, 2020 at 7:20
  • make sure your collection 'users' is observable and check for errors in the browser console Commented Aug 31, 2020 at 7:21
  • i will add my component.ts code.Guide me @ArmenStepanyan Commented Aug 31, 2020 at 7:22
  • my users is observable only and my browser console doens't throwing any errors @MujassirNasir Commented Aug 31, 2020 at 7:25

2 Answers 2

1

It seems you receive an array and not an object. You could simply map the received data and keep the rest.

reloadData() {
    this.users = this._service.getUserList().pipe(
      map(arrayUsers => arrayUsers.map(arrayUser => ({
        id: arrayUser[0],
        email: arrayUser[1],
        firstname: arrayUser[2],
        lastname: arrayUser[3],
      })))
    );
  }
Sign up to request clarification or add additional context in comments.

Comments

0

Your output seems to be CSV kind (array of an array) not the JSON. So, you need to use {{user[1]}} for email instead of {{user.email}} and {{user[2]}} for firstname instead of {{user.firstname}}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.