Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs Typescript/Angular-在模态结果返回后调用分离函数_Angularjs_Typescript_Bootstrap Modal_Angular Promise_Angular Bootstrap - Fatal编程技术网

Angularjs Typescript/Angular-在模态结果返回后调用分离函数

Angularjs Typescript/Angular-在模态结果返回后调用分离函数,angularjs,typescript,bootstrap-modal,angular-promise,angular-bootstrap,Angularjs,Typescript,Bootstrap Modal,Angular Promise,Angular Bootstrap,当通过关闭或取消Angular/Typescript中的模式返回我的承诺时,调用单独的函数时出现问题。也许我试图做一些不可能的事情,但我看到的所有示例要么将返回的数据记录回控制台,要么记录到变量,要么抛出警报。像这样: modalInstance.result.then(function (result) { console.log(result); }); 我希望在返回结果后调用一个单独的函数,如: modalInstance.result.then(function (result

当通过关闭或取消Angular/Typescript中的模式返回我的承诺时,调用单独的函数时出现问题。也许我试图做一些不可能的事情,但我看到的所有示例要么将返回的数据记录回控制台,要么记录到变量,要么抛出警报。像这样:

modalInstance.result.then(function (result) {
    console.log(result);
});
我希望在返回结果后调用一个单独的函数,如:

modalInstance.result.then(function (result) {
    console.log(result);
    this.EditWidget(result);
});
但这不起作用,我似乎不明白为什么。我已经尝试了所有的事情,我想我只是错过了一些关于承诺如何在这里起作用的东西


有什么想法吗?

我的观点是,
这并不是你所期望的。您需要捕获该值,并在回调中使用捕获的值:

var that = this;
modalInstance.result.then(function (result) {
    console.log(result);
    that.EditWidget(result);
});
或将函数绑定到此:

var callback = function (result) {
    console.log(result);
    this.EditWidget(result);
};

modalInstance.result.then(callback.bind(this));

我看不出你发布的代码有任何错误。是什么让你认为有错误?该功能是否超出了承诺范围?你能提供更多的代码来展示你在做什么吗?太棒了!非常感谢!