i am trying to assign data to dtOptions - but not works. what is the correct way to do it?

here is my function:

 getDatas(){
        this.datas = this.http.get('data/data.json').subscribe(values =>  values);//values available  here
    }

    ngOnInit() {

        this.categoryListCopy = this.categoryList;
        this.getDatas()

        const that = this;
        this.dtOptions = {

            columns:[{
                data: 'id'
            }, {
                data: 'firstName'
            }, {
                data: 'lastName'
            }],
            pagingType: 'full_numbers',
            pageLength: 10,
            serverSide: false,
            processing: true,
            ajax: this.datas
            };



        }

1 Answers

1
CodeReady On Best Solutions

You just need to use Observable, your code will look like this:

getDatas(): Observable{
        return this.http.get('https://jsonplaceholder.typicode.com/todos/1');
    }

  ngOnInit() {
        this.getDatas().subscribe(values =>  {
           console.log(values);
           // You can assign dtOptions here, you will have your data in values.
        });      
  }

You can find the working plunk here.