Typescript Service在声明之前不使用块作用域变量'place'的错误

时间:2017-12-21 08:16:24

标签: typescript service

import {Place} from "../models/place";
import {Location} from "../models/location";

export class PlacesService {
     private places: Place[] = [];


     addPlace(title: string,
              description: string,
              location: Location,
              base64Image: string){
         ***let place = new place(title,description,location,base64Image);***
          this.places.push(place);

     }

     loadPlaces(){
          return this.places.slice();
     }
}

1 个答案:

答案 0 :(得分:0)

本声明

let place = new place
    ^^^^^       ^^^^^

会引发错误,因为您要创建place的实例,该实例在构造函数中被声明为变量,并且您没有初始化它。您的模型名称为Place(第一个字母为大写),而不是place

let place = new Place(...)