等待我的功能完成返回我的价值角度角度
在异步问题上,我被阻止了代码。 我有3个FCT,由我的组件调用1个,然后返回一个值:
getMenu(): Observable<Menu> {
this.recupUser();
return of(this.menu);
}
在这里,我调用我的函数recupuser(),它可以执行HTTP获取请求,然后将我的数据选中:
recupUser() {
return this.loginService.recupConnectedUser().subscribe(
{
next: value =>{
this.User = value;
this.initMenu()
},
}
)
} 我的var用户在initmenu()上使用,然后我必须在订阅中调用此fct以获取用户的价值。 然后在initmenu()我做一个条件:
initMenu() {
if (this.User.es = '04840') {
this.menu = {
leftMenu: [
{title: 'Title 1', id: '1', role: '/URL1'},
{title: 'Title 2', id: '2', role: '/URL2'},
],
rightMenu: [
{icon:'profile',tooltip:'Profile', id:'profile', role:'/'},
]
};
} else {
this.menu = {
leftMenu: [
{title: 'Title1', id: '1', role: '/URL1'},
],
rightMenu: [
{icon:'profile',tooltip:'Profile', id:'profile', role:'/'},
]
};
} }
然后,我在最后一个FCT中初始化菜单。我已经尝试了可能的事情,但是我没有等待所有完成我的价值。我在异步王子中遇到了一些困难,因此可能欢迎任何帮助!
i'm blocked on my code on an async problem.
I have 3 fct, 1 is called by my component and return a value:
getMenu(): Observable<Menu> {
this.recupUser();
return of(this.menu);
}
Here i call my function recupUser() which does an http get request, and i take my data in var :
recupUser() {
return this.loginService.recupConnectedUser().subscribe(
{
next: value =>{
this.User = value;
this.initMenu()
},
}
)
}
My var User is used on initMenu() then i have to call this fct in my subscription to get value in User.
Then in initMenu() i do an condition :
initMenu() {
if (this.User.es = '04840') {
this.menu = {
leftMenu: [
{title: 'Title 1', id: '1', role: '/URL1'},
{title: 'Title 2', id: '2', role: '/URL2'},
],
rightMenu: [
{icon:'profile',tooltip:'Profile', id:'profile', role:'/'},
]
};
} else {
this.menu = {
leftMenu: [
{title: 'Title1', id: '1', role: '/URL1'},
],
rightMenu: [
{icon:'profile',tooltip:'Profile', id:'profile', role:'/'},
]
};
}
}
then i initialise my menu in this last fct. i've tried may things but i don't reach to wait that all finish to return my value. i have some difficulties with the asynchrone principe so any help may be welcome !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
rxjs operator
使用
use rxjs operator
in class