javascript - 如何在 $http body angularjs 中调用方法

标签 javascript angularjs angularjs-directive angularjs-scope

我想在我的其他方法中调用 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;
      }

最佳答案

为此目的使用函数引用,希望这会对您有所帮助。

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

关于javascript - 如何在 $http body angularjs 中调用方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41277921/

相关文章:

javascript - bootstrap-select + typescript + webpack 在简单示例中无法正确呈现

angularjs - 带 promise 的 Ionic 2 无法正确刷新 View

angularjs - $rootScope.$on 多次调用

javascript - AngularJS 1.4 : How to create two-way binding using bindToController and controllerAs syntax

angularjs - 两个单独指令之间的通信

angularjs - 如何将 ng-repeated 对象传递给我的 AngularJS 指令?

javascript - colorbox 在不关闭弹出窗口的情况下刷新父窗口

javascript - 如何将 for 循环添加到以下 JavaScript 以验证输入?

javascript - 获取 Algolia 索引中的记录总数 - Javascript

javascript - 手动显示 AngularStrap 下拉列表 - 如何?