angular - Angular:在函数和 api 调用之外访问变量
问题描述
Angular 和 JS 的超级新手,运行版本 10,你到底如何在服务调用后获取数组数据?任何有关如何执行此操作的提示将不胜感激。数组在调用内部是完整的,但从不在外部。我怎样才能得到它,以便我可以在我的 html 模板中使用该数组?
// PROBLEM, as noted where undefined below.
selectScript(s_id, r_id, prompts: Prompt, scripts: Script){
this.apiService.readScript(s_id).subscribe((scripts: Script[])=>{
this.scripts = scripts;
// console.log(scripts); // Array OK
});
this.apiService.readPrompts(r_id).subscribe((prompts: Prompt[])=>{
this.prompts = prompts;
//console.log(prompts); // Array OK
});
console.log(this.scripts); // Undefined! How to get array here?
this.ud = true;
this.ngOnInit();
}
解决方案
推荐阅读
- java - 实现类导致“重复类错误
- junit - jMockit 代码覆盖工具:如何在 Eclipse 运行配置中激活?
- python - 关于为什么列表列表的处理失败的问题
- javascript - Array.fill 函数在反应中不起作用
- javascript - 删除 EventListener 上的转换:
- markdown - 构造一个包含许多节和小节的 Markdown 文件
- material-ui - material-ui 创建许多重复的类
- curl - 带有用户名/密码身份验证的 curl 失败
- c# - 异步任务中的 ASP.NET EF Core 连接问题
- vbscript - 列出文件/子文件的名称、大小和创建日期?