打字稿错误';'预期

时间:2017-05-08 16:14:38

标签: typescript ionic2

我不知道为什么我会收到这些错误。到目前为止,我已经检查过,我不认为语法不正确或缺少某些东西。可能是我错了。请看一下我的代码:

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.

2 个答案:

答案 0 :(得分: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;
  });
}

我猜你错过了一个&#34 ;;"在捕获之后还有一个"("在那之后。

答案 1 :(得分:0)

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

coords可以改为

coords: number

然后你会有打字稿安全