ionic , angular - index.html 内的全局变量将被其他 ts 页面调用
ionic , angular - global variable inside index.html to be called by other ts pages
组件(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;
}
组件(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;
}