Javascript 离子2如何使用常量变量';s在index.html中声明?
我在爱奥尼亚2中创建了一个安卓应用程序。我在index.html的脚本标记中声明了一个变量。我想在ionic 2页面和提供程序代码中使用这个常量值。我把代码贴在下面。先谢谢你 index.htmlJavascript 离子2如何使用常量变量';s在index.html中声明?,javascript,angular,typescript,ionic-framework,ionic2,Javascript,Angular,Typescript,Ionic Framework,Ionic2,我在爱奥尼亚2中创建了一个安卓应用程序。我在index.html的脚本标记中声明了一个变量。我想在ionic 2页面和提供程序代码中使用这个常量值。我把代码贴在下面。先谢谢你 index.html 离子的 BASE_APP_URL=“www.google.com”; 项目详细信息。ts 从'@angular/core'导入{Component}; 从“离子角度”导入{NavController,NavParams}; @组成部分({ templateUrl:'build/pages/
离子的
BASE_APP_URL=“www.google.com”;
项目详细信息。ts
从'@angular/core'导入{Component};
从“离子角度”导入{NavController,NavParams};
@组成部分({
templateUrl:'build/pages/item details/item details.html'
})
导出类ItemDetailsPage{
selectedItem:any;
构造函数(公共navCtrl:NavController,navParams:navParams){
this.selectedItem=navParams.get('item');
console.log(基本应用程序URL);
}
}
即使在Ionic应用程序中处理静态设置的更好方法是中的方法,您也可以通过以下方法使代码正常工作:
之前包含脚本和变量,因为这是您要使用它的地方窗口
对象的一部分
<!-- Your variable -->
<script type="text/javascript">
window.BASE_APP_URL="www.google.com";
</script>
<!-- the bundle which is built from the app's source code -->
<script src="build/js/app.bundle.js"></script>
尽管如此,我仍然建议在任何Ionic 2应用程序中处理静态设置。正确的方法是。感谢回复@sebafereras!!我用了第二种方法…而且很有效。。
import {Component} from '@angular/core';
import {NavController, NavParams} from 'ionic-angular';
@Component({
templateUrl: 'build/pages/item-details/item-details.html'
})
export class ItemDetailsPage {
selectedItem: any;
constructor(public navCtrl: NavController, navParams: NavParams) {
this.selectedItem = navParams.get('item');
console.log(window.BASE_APP_URL);
}
}