等到“ Angular Observable”完成

时间:2018-11-16 20:38:55

标签: angular rxjs observable

环顾四周,没有发现任何适合我的问题。我如何使其余的.ts代码等待可观察的对象完成。

我是Angular的新手,仍然试图弄清楚Observable的工作原理。我熟悉在模板中使用'|异步”,但使用它们在我的.ts文件中获取数据无法正常工作。

我希望一切都等待Observable完成后再继续。我的目标是根据我的观察对象的响应将类变量设置为“简明”。

我将使用该变量

不幸的是,简报变量永远不会改变。我很肯定这是我的基本误会。

我的课程基本上可以归结为:

export class briefValidatorComponent implements OnInit{
    briefed: boolean = false;
    output: customObjectTwo;

    @Input() inputOne: customObject;
    @Input() inputTwo: customObject;

    ngOnIt(){
        this.userService
            .getBriefingReflectedForUser()
            .subscribe(response => {
                this.briefed = response.briefingInCasport; //Returns true
                console.log(this.briefed); //Prints true
            });

        console.log(this.briefed); //Prints false

        functionOne(objectOne, objectTwo);
    }

    functionOne(objectOne, objectTwo){
        //does some work with the briefed variable to 
        //determine what the output will be
}

编辑:对不起,我的意图应该更完整。尚未编写其余代码,因为我在这里很困惑。

我将拥有另一个函数,该函数评估一些输入数据以确定输出是什么。然后,我将在自己的dom中引用该输出以更改将在此处显示的内容。

我研究了订阅方法中的所有工作,但后来无法更改dom的输出以供参考。

0 个答案:

没有答案
相关问题