我有2个功能。我正在从一个函数中获取数据,如何从另一个函数中调用数据值
这是代码示例
export class IntroPage {
fun1() {
this.messageService.getGroupMessages(this.group_id).subscribe( (data:any) => {
console.log(data);
this.groupname = data.groupname; // As here need to show this.groupname in second function
});
}
fun2() {
console.log(this.groupname); // Need to show value here
}
}
我知道我可以通过像this.fun2(this.groupname);
这样的函数传递值,但是我不想这样做。有什么方法可以显示而不通过函数传递或在文件中全局设置?