angular - 带角度的 Chrome 扩展:无法使用 chrome API 初始化字段
问题描述
我正在尝试用 Angular 编写一个 chrome 扩展。我为弹出窗口编写了以下组件
@Component({
selector: 'app-root',
template: ` Current tab: {{ currentTab || '(empty)' }} `,
styles: []
})
export class AppComponent implements OnInit {
currentTab: string;
ngOnInit(): void {
this.getCurrentTabTitle().subscribe(title => this.currentTab = title);
}
getCurrentTabTitle() {
return new Observable<string>(subscriber => {
chrome.tabs.query({ active: true, currentWindow: true }, tabs => {
subscriber.next(tabs[0].title);
});
});
}
}
tabs.query()
确实调用了回调,但内容仍然存在"Current tab: (empty)"
。为什么会这样?
解决方案
推荐阅读
- python - 具有 2 个域的 Django 2.2
- amazon-web-services - 如何解决 AWS Elastic Beanstalk 中的“容器命令构建失败”一般错误?
- python - 或工具 Constraint_SetCoefficient 返回 NULL 而不设置错误
- python - EOFError:加载时输入不足
- android - 在 Android Studio 中使用 GitHub 库
- c++ - 将列表的索引与字符串进行比较时遇到问题
- sql - SQL中按a-->b-->c-->d顺序查找有事件的客户id
- php - PHP用链接中的字符串连接变量
- python - 单个 Dataframe pandas 中 2 列的交集
- regex - IIS URL 的正则表达式根据 URL 中的参数从一个域重写到其他域