我試圖改變離子狀態欄的顏色取決於獲取的參數。離子2 - 動態改變狀態欄的顏色
onDeviceReady()
函數中只有colorStatusBar
變量顯示爲undefined
。
有人可以幫我解決這個問題嗎?
typeColor: string;
colorStatusBar: string;
constructor(public navCtrl: NavController, public navParams: NavParams, statusBar: StatusBar){
this.typeColor = this.navParams.get('type');
if(this.typeColor == "value1"){
this.colorStatusBar = "#F44336";
}
if(this.typeColor == "value2"){
this.colorStatusBar = "#66BB6A";
}
if(this.typeColor == "value3"){
this.colorStatusBar = "#9E9E9E";
}
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
console.log(this.colorStatusBar) // undefined
statusBar.backgroundColorByHexString(this.colorStatusBar);
}
}
裏面的'this.platform.ready(),然後(()=> {的console.log(this.typeColor)\\ undefined'變量。仍然是'undefined' – rafaelcb21
雖然這與你的問題沒有關係(動態改變狀態欄的顏色),這是一個在不傳入'type'參數的情況下(從另一個頁面)進入這個頁面的問題。任何情況下,我也編輯了我的帖子,並附上說明。 – maninak