Home:ALL Converter>pdfmake + angularjs passing variables

pdfmake + angularjs passing variables

Ask Time:2016-12-17T21:06:48         Author:Luca5om3

Json Formatter

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


         });
  }

Author:Luca5om3,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/41198886/pdfmake-angularjs-passing-variables
yy