Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.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
Angular 如何检查一个函数是否完成,然后调用另一个函数_Angular_Typescript_Methods_Angular6 - Fatal编程技术网

Angular 如何检查一个函数是否完成,然后调用另一个函数

Angular 如何检查一个函数是否完成,然后调用另一个函数,angular,typescript,methods,angular6,Angular,Typescript,Methods,Angular6,我需要检查用户是否为某个项目选择了表单,然后在提交带有新值的表单时重定向到另一个页面 HTML: 为了简短起见,我需要检查某个字段的值是否已更改,然后将用户重定向到所需的组件。它总是重定向到['/pacient/ra',this.id]);仅当从列表中选择新治疗时,我需要重定向de user。所有这些活动都将在提交表单时开始…例如,您可以将原始值和更改后的值保留为单独的变量 originalTratament: any; newTratament: any; 然后在onChange()中,您可

我需要检查用户是否为某个项目选择了表单,然后在提交带有新值的表单时重定向到另一个页面

HTML:


为了简短起见,我需要检查某个字段的值是否已更改,然后将用户重定向到所需的组件。它总是重定向到['/pacient/ra',this.id]);仅当从列表中选择新治疗时,我需要重定向de user。所有这些活动都将在提交表单时开始…

例如,您可以将原始值和更改后的值保留为单独的变量

originalTratament: any;
newTratament: any;
然后在
onChange()
中,您可以设置如下新值:

private onChange(TratamentAValue): any {
    this.newTratament = TratamentAValue;
}
最后,您可以比较变量以检查它们是否不同:

onChangeSubmit(){
    const CONDITION = this.originalTratament != this.newTratament;
    const DATA = this.onChange(this.TratamentAValue);
    const ERROR = new Error(this.goBack())

    const promise =
        new Promise((resolve, reject) => {
            // do some async stuff
            this.router.navigate(['/pacient/ra', this.id]);

            if (CONDITION) resolve(DATA);
            else reject(ERROR);
        })

    updatePacient() {
        this.pacService
            .updatePacient(this.model)
            .subscribe(() => this.onChangeSubmit());

    }
}

您可能会更改某些内容,因为我不知道您的数据结构

非常感谢您的努力,但仍然无法工作,我离您很近。提交新值后,仍将重定向到(this.goBack()),而不是重定向到/pacient/ra。。。我认为数据并没有以某种方式得到解决。问题是,在提交表单时更改处理方式的用户必须重定向到SideEffects页面。api上的一切工作正常,所有…都出现了一个错误:未捕获(承诺):[object Undefined]在提交时未选择newTreatment。
originalTratament: any;
newTratament: any;
private onChange(TratamentAValue): any {
    this.newTratament = TratamentAValue;
}
onChangeSubmit(){
    const CONDITION = this.originalTratament != this.newTratament;
    const DATA = this.onChange(this.TratamentAValue);
    const ERROR = new Error(this.goBack())

    const promise =
        new Promise((resolve, reject) => {
            // do some async stuff
            this.router.navigate(['/pacient/ra', this.id]);

            if (CONDITION) resolve(DATA);
            else reject(ERROR);
        })

    updatePacient() {
        this.pacService
            .updatePacient(this.model)
            .subscribe(() => this.onChangeSubmit());

    }
}