pdfmake + angularjs passing variables

911 Views Asked by At

I have this code inside my angular controller, I took pdfmake dynamic table code from here I want to pass json response to table function inside var dd, but it says it's undefined, I tried console.log(jsontopdf) directly inside .success() and it works, so json is correctly passed through API...
what I did wrong?

  $http.post('/cambio', toElab)
         .success(function(data) {
          jsontopdf = data;

          var dd = {
             content: [
                 { text: 'Dynamic parts', style: 'header' },
                 table(jsontopdf, ['a', 'b','c'])
             ]
         }


        function table(data, columns) {
            return {
                table: {
                    headerRows: 1,
                    body: buildTableBody(data, columns)

                }
            };
        }

        function buildTableBody(data, columns) {
          var body = [];

          body.push(columns);

          angular.forEach(data, function(row) {
              var dataRow = [];

              angular.forEach(columns, function(column) {
                  dataRow.push(row[column].toString());
              })

              body.push(dataRow);
          });

          return body;
      }


         });
  }
1

There are 1 best solutions below

0
On

OK, I figured it out, my Json comes from a Jackson ArrayNode, i made it work by applying JSON.stringify and than JSON.parse on var jsontopdf...

There is some kind of more sensed conversion that I missed?