“本地”的所有声明在离子2中必须具有相同的修饰物

时间:2016-10-04 21:24:35

标签: angular typescript ionic-framework ionic2

当我使用local:storage变量时出现此错误。 我只想注意到它只是在一小时之前发生的。在此之前它运作良好。

当我尝试通过" ionic serve"运行应用程序时显示此错误。 error

这是我的服务

import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';
import {NavController} from "ionic-angular";

import { Storage } from '@ionic/storage';
/*
  Generated class for the Myservice provider.

  See https://angular.io/docs/ts/latest/guide/dependency-injection.html
  for more info on providers and Angular 2 DI.
*/
@Injectable()
export class MyService {

  public local:Storage;
  public getsession: any;


  constructor(public http: Http,private local: Storage,private navCtrl:NavController) {
    this.local=new Storage();

  }
  postLogin(data){
    let link = "http://adirzoari.16mb.com/login.php";
    return this.http.post(link,data)
        .map(res => res.json())
  }
  checkToken(){
    return this.getsession =this.local.get('token');

  }
  getData(){
    let link = "http://adirzoari.16mb.com/selectNotes.php";
    return this.http.get(link)
        .map(res=>res.json())
  }
  postInsert(data){
    let link="";
    return this.http.post(link,data)
        .map(res=>res.json())
  }
  postUpdate(data){
    let link="";
    return this.http.post(link,data)
        .map(res=>res.json())
  }
  postDelete(data){
    let link = "http://adirzoari.16mb.com/deleteNotes.php";
    return this.http.post(link,data)
        .map(res => res.json())
  }
}

另外, 我收到这个错误 new error

2 个答案:

答案 0 :(得分:2)

这是因为您还将本地声明为public local:Storage;,并且在构造函数中也声明为私有,如下所示:

constructor(public http: Http,private local: Storage,private navCtrl:NavController) {

修复

删除public local:Storage;

答案 1 :(得分:1)

  

我改变了它,但我从中得到了新的错误返回类型的公共方法   导出的类具有或正在使用名称' observable' ...

为了解决该问题,您需要显式导入Observable类:

import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';
import { Observable } from "rxjs/Observable"; // <- add this import
import {NavController} from "ionic-angular";