0

I want to call editopenComponentModal in my other method its show error angular.js:13920 TypeError: Cannot read property 'editopenComponentModal' of undefined

   EditCurrentJob(job) {

          this.$http.put(properties.job_path + "/"+job.job_id).then(function successCallback(response) {
            console.log(response.data);
            this.current_job =  response.data;
            this.editopenComponentModal();

         }, 
          function errorCallback(response) {

          });
}

     editopenComponentModal() {
        var modalInstance = this.$uibModal.open({
          animation: this.animationsEnabled,
          template: require('./Report/editsubmittedinformation.html'),
          scope: this.$scope,
          size: 'lg'
        });
        this.$scope.modalInstance = modalInstance;

        return modalInstance.result;
      }
Addi Khan
  • 37
  • 4
  • 11

3 Answers3

1

Use the function references for that purpose, jopefully this will help you out.

var vm = this;
vm.editopenComponentModal = editopenComponentModal;
function EditCurrentJob(job) {

      $http.put(properties.job_path + "/"+job.job_id).then(function successCallback(response) {
        console.log(response.data);
        vm.current_job =  response.data;
        vm.editopenComponentModal();

     }, 
      function errorCallback(response) {

      });
}

 function editopenComponentModal() {
    var modalInstance = this.$uibModal.open({
      animation: this.animationsEnabled,
      template: require('./Report/editsubmittedinformation.html'),
      scope: this.$scope,
      size: 'lg'
    });
    this.$scope.modalInstance = modalInstance;

    return modalInstance.result;
  }
Mr_Perfect
  • 8,254
  • 11
  • 35
  • 62
Ahmer Khan
  • 747
  • 1
  • 10
  • 31
0

If you want to open a modal after $http.put request then use.

  $('#success').modal();

here success is the id.

sac Dahal
  • 1,191
  • 2
  • 13
  • 37
0

Add var that = this above the this.$http.put(

Then change:

this.current_job = response.data;

this.editopenComponentModal();

To:

that.current_job = response.data;

that.editopenComponentModal();

Explanation: this inside the callback has different context, so you need to save the desired this to a variable which can be used there.

Here you can read the better explanation: How to access the correct `this` context inside a callback?

Community
  • 1
  • 1