Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/462.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
Javascript:从嵌套函数调用外部方法_Javascript_Typescript_Ecmascript 6_Ecmascript 5 - Fatal编程技术网

Javascript:从嵌套函数调用外部方法

Javascript:从嵌套函数调用外部方法,javascript,typescript,ecmascript-6,ecmascript-5,Javascript,Typescript,Ecmascript 6,Ecmascript 5,我想调用openSnackBar,但出现异常。任何人都可以帮助我如何处理嵌套函数的外部方法调用吗 export class DetailsComponent implements OnInit, OnDestroy { updateTodoPromise.then(function (fulfilled) { // yay, you got a new phone this.openSnackBar('Task saved successfully

我想调用
openSnackBar
,但出现异常。任何人都可以帮助我如何处理嵌套函数的外部方法调用吗

export class DetailsComponent implements OnInit, OnDestroy
{
updateTodoPromise.then(function (fulfilled) {
            // yay, you got a new phone
            this.openSnackBar('Task saved successfully!', 'CLOSE');
        })
        .catch(function (error) {
            // ops, mom don't buy it
            console.log(error.message);
            this.openSnackBar('Task saved successfully!','CLOSE');
        });

    }

    public openSnackBar(full: string, full2: string) {
        this.snackBar.open(full, full2, {
            duration: 5000,
        });
    }

使用ES6双箭头表示法保留
范围

export class DetailsComponent implements OnInit, OnDestroy
{
updateTodoPromise.then( fulfilled => { // <--- here
            // yay, you got a new phone
            this.openSnackBar('Task saved successfully!', 'CLOSE');
        })
        .catch( error => {  // <--- and here
            // ops, mom don't buy it
            console.log(error.message);
            this.openSnackBar('Task saved successfully!','CLOSE');
        });

    }

    public openSnackBar(full: string, full2: string) {
        this.snackBar.open(full, full2, {
            duration: 5000,
        });
    }
导出类详细信息组件实现OnInit、OnDestroy
{

updateTodoPromise.then(completed=>{/{/使用ES6双箭头表示法来保留
这个
范围

export class DetailsComponent implements OnInit, OnDestroy
{
updateTodoPromise.then( fulfilled => { // <--- here
            // yay, you got a new phone
            this.openSnackBar('Task saved successfully!', 'CLOSE');
        })
        .catch( error => {  // <--- and here
            // ops, mom don't buy it
            console.log(error.message);
            this.openSnackBar('Task saved successfully!','CLOSE');
        });

    }

    public openSnackBar(full: string, full2: string) {
        this.snackBar.open(full, full2, {
            duration: 5000,
        });
    }
导出类详细信息组件实现OnInit、OnDestroy
{
然后(完成=>{/{//