我在離子2中創建一個android應用程序。我在index.html中的腳本標記中聲明瞭一個變量。這個常數值我想在離子2頁和提供者代碼中使用。我粘貼下面的代碼。在此先感謝...ionic 2如何在index.html中使用常量變量的聲明?
的index.html
<html lang="en">
<head>
<title>Ionic</title>
<meta charset="UTF-8">
<link ios-href="build/css/app.ios.css" rel="stylesheet">
<link md-href="build/css/app.md.css" rel="stylesheet">
<link wp-href="build/css/app.wp.css" rel="stylesheet">
</head>
<body>
<ion-app></ion-app>
<!-- cordova.js required for cordova apps -->
<script src="cordova.js"></script>
<script src="build/js/es6-shim.min.js"></script>
<!-- Zone.js and Reflect-metadata -->
<script src="build/js/Reflect.js"></script>
<script src="build/js/zone.js"></script>
<!-- the bundle which is built from the app's source code -->
<script src="build/js/app.bundle.js"></script>
<script type="text/javascript">
BASE_APP_URL="www.google.com";
</script>
</body>
</html>
項目,details.ts
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(BASE_APP_URL);
<!---it gives an error that name
Error TS2304: Cannot find name 'BASE_APP_URL'. -->
}
}
正確的做法是[this one](http://stackoverflow.com/questions/38937503/where-to-save-settings-like-api-url-in-ionic2-app/38940262# 38940262)。 – sebaferreras