ERROR TypeError: Cannot read property 'http' of undefined


#1

Hi I must be doing some thing wrong here plaease assist I am getting this error

ERROR TypeError: Cannot read property ‘http’ of undefined

let postItem= new Object({
        title:issue.title,
        issueDate:issue.issueDate,
        auditor:issue.auditor,
        issueSourceId:issue.issueSource.id,
        findings:[
          {
            title:item.title,
            issueDetails:item.issue,
            imageUrl:item.imageUrl,
            signature:item.signature,
            foodSafetyCategoryId:item.foodSafetyCategory,
            areaId:item.area,
            natureId:item.nature,
            severityId:item.severity

          }, ]
});
      let headers = new Headers({'Content-Type': 'application/json'});
      let options = new RequestOptions({ headers: headers });

      this.http.post(this.postUrl,JSON.stringify(postItem),options).
      map(res => res.json()).
      subscribe(data=>
        console.log(data));
    })
  }

and in constructor I have

public http: Http

#2

I suspect you are not showing us the entire context.


#3

@rapropos you are right there is a block I thought would not be affecting the posting part and here it is

uploadIssue(issue) {

    var images = []
   
    var items = issue.findings.map(function (item) {
      console.log(item.imageUrl);
      var image = new Image();
      var imageData = '';

      image.onload = function () {
       
        var canvas: any = document.createElement('CANVAS'),
          ctx = canvas.getContext('2d'),
          dataURL;
        canvas.width = 100;
        canvas.height = 100;

        ctx.drawImage(this, 0, 0);
        dataURL = canvas.toDataURL('image/png');
        console.log(dataURL);
        // imageData=dataURL;
        var _image = {
          image: dataURL
        }
        images.push(_image)
       
      };
      image.src = item.imageUrl;

      let postItem= new Object({
        title:issue.title,
        issueDate:issue.issueDate,
        auditor:issue.auditor,
        issueSourceId:issue.issueSource.id,
        findings:[
          {
            title:item.title,
            issueDetails:item.issue,
            imageUrl:item.imageUrl,
            signature:item.signature,
            foodSafetyCategoryId:item.foodSafetyCategory,
            areaId:item.area,
            natureId:item.nature,
            severityId:item.severity

          },


        ]

      });


      let headers = new Headers({'Content-Type': 'application/json'});
      let options = new RequestOptions({ headers: headers });

      this.http.post(this.postUrl,JSON.stringify(postItem),options).
      map(res => res.json()).
      subscribe(data=>
        console.log(data));
    })



  }

 

I initially had the post in a service and it gave me the same error i moved it to this page to try and trouble shoot

Thanks


#4

Thanks so much for the link that works and quite an important learning point I have had similar issues many times with using this. in functions