在promise angular2中找不到名字

时间:2018-02-09 08:24:05

标签: angular

  public abc: any[];
        prop: any[];
        xyz: any[];
        public ab;
        public query = '';
        ngOnInit() {
           var ww =this.getCityData();**strong text**
        }

        constructor(myElement: ElementRef,public http: Http,public fb: FormBuilder,private router:Router) {
            this.elementRef = myElement;
            this.selectedIdx = -1;


        }


        async getCityData(): Promise<xyz[]> {
          try {
            let response = await this.http
              .get('http://localhost/ang/rst/getCityData.php')
              .toPromise();
            return response.json().data as xyz[];
          } catch (error) {
            await this.handleError(error);
          }
        }


        private handleError(error: any): Promise<any> {
            console.error('An error occurred', error); // for demo purposes only
            return Promise.reject(error.message || error);
         }

/opt/lampp/htdocs/real/src/app/home.component.ts(41,30)中的错误:找不到名称&#39; xyz&#39;。

/opt/lampp/htdocs/real/src/app/home.component.ts(46,36)中的错误:找不到名称&#39; xyz&#39;。

1 个答案:

答案 0 :(得分:0)

return response.json().data as xyz[];

xyz[]不是一种类型。请改用any[]