angular - ionic , angular - index.html 中的全局变量,由其他 ts 页面调用
问题描述
组件(ts 文件)如何访问 index.html 中的变量?例子:
内部:index.html
<javascript>
var myVar = "test";
</javascript>
如何让这个变量“myVar”在组件页面中使用
例如在组件 html 上使用,例如 {{myVar}}
解决方案
在 ts 文件中,您可以像这样声明它:
//Other imports
declare var myVar: any;
@Component({
selector: 'my-component',
templateUrl: './my-component.component.html',
styleUrls: ['./my-component.component.scss']
})
export class MyComponent {
my_javascript_variable = myVar;
}
推荐阅读
- java - 如何使用 Mockito 测试 CompletableFuture 类的 handle() 方法?
- mysql - 如何使用 MYSQL 选择不在列表中的值
- android - Android Studio IDE - 设计编辑器中不显示任何元素
- ios - 如何在不询问 iOS Swift 登录的情况下自动登录?
- jquery - 要在文本框中输入金额,值会自动转换为成本格式吗?
- avplayer - 关于 KVO key path operationCount 的 AVPlayerLayer 崩溃
- apple-push-notifications - 使用 http2 的 Apns 推送主题
- php - 为什么我在 Laravel 中收到此错误?
- node.js - 通过 safe-Url 使用 NodeJS 客户端 API 查询数据存储实体
- asp.net - Asp MVC 模型实体验证不显示必需的错误