我想在我的其他方法中调用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;
}
答案 0 :(得分: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;
}
答案 1 :(得分:0)
如果你想在$ http.put请求后打开一个模态,那么使用。
$('#success').modal();
这里的成功就是身份。
答案 2 :(得分:0)
在var that = this
this.$http.put(
然后改变:
this.current_job = response.data;
this.editopenComponentModal();
要:
that.current_job = response.data;
that.editopenComponentModal();
说明:
回调中的this
具有不同的上下文,因此您需要将所需的this
保存到可在此处使用的变量。
在这里你可以阅读更好的解释: How to access the correct `this` context inside a callback?