2017-05-08 58 views
0

我不知道爲什麼我得到這些錯誤。據我檢查,我不認爲語法不正確或缺少某些東西。可能是我錯了。請在我的代碼來看看:Typescript Error';'預計

import { Component } from '@angular/core'; 
import { NavController } from 'ionic-angular'; 
import { Geolocation } from '@ionic-native'; 

@Component({ 
    selector: 'page-home', 
    templateUrl: 'home.html' 
}) 
export class HomePage { 
coords:any; 
accuracy:any; 
error:any; 

    constructor(public navCtrl: NavController) { 

    } 

watch(){ 
    Geolocation.getCurrentPosition().then(resp) => { 
    this.coords= resp.coords.latitude+' '+resp.coords.longitude; 
    this.accuracy= resp.coords.accuracy+' '+'meters'; 
    }).catch((error)=>{ 
    this.error='Error getting location'+error; 
    }) 
} 

} 

//這是錯誤日誌中簡要:

Typescript Error 
';' expected. 

Typescript Error 
Declaration or statement expected. 

Typescript Error 
'try' expected. 

回答

1

試試這個:

watch(){ 
    Geolocation.getCurrentPosition().then((resp) => { 
    this.coords= resp.coords.latitude+' '+resp.coords.longitude; 
    this.accuracy= resp.coords.accuracy+' '+'meters'; 
    }).catch((error)=>{ 
    this.error='Error getting location'+error; 
    }); 
} 

我猜你是缺少「; 「在漁獲物和也「(」後即可。

+1

感謝。我的壞。 – camoflage

+0

你」歡迎:) –

+0

使用兼容的IDE,如VSCode,所以你不必手動發現錯誤。 – unional

0
coords:any; 
accuracy:any; 
error:any; 

COORDS可改爲

coords: number 

,然後你會打字稿安全後