0

Я хочу назвать editopenComponentModal в моем другом методе его шоу ошибки 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; 
     } 

ответ

1

Используйте ссылки функции для этой цели, jopefully это поможет вам.

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

Если вы хотите открыть модальный после $ http.put запрос затем использовать.

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

здесь успех - это идентификатор.

0

Добавить var that = this выше this.$http.put(

Затем измените:

this.current_job = response.data;

this.editopenComponentModal();

To:

that.current_job = response.data;

that.editopenComponentModal();

Объяснение: this внутри обратного вызова имеет другой контекст, так что вам нужно, чтобы сохранить нужный this к переменной, которая может быть использована там.

Здесь вы можете прочитать лучшее объяснение: How to access the correct `this` context inside a callback?

+0

ReferenceError: это не определено –