TypeError:v.context。$ implicit不是函数

时间:2017-04-19 16:47:04

标签: typescript ionic2

我是Typescript的新手。已经3天了。我想从Firebase访问数据。我访问并列出。当我想通过(Click)=" item()"传递到另一个页面时出现错误。我在哪里做错了。

数据-api.service.ts

import {Injectable} from '@angular/core';
import {Http,Response} from '@angular/http';

import 'rxjs';
import {Observable} from 'rxjs/Observable';
@Injectable()

export class DataApi {


 private url = 'https://ionic2-9dc0a.firebaseio.com/.json';   // https://ionic2-9dc0a.firebaseio.com

 currentphone : any = {};
constructor(private http:Http){
}
  getAdress(){
    return new Promise(resolve =>{
      this.http.get(`${this.url}`) 
      .subscribe(res => resolve(res.json()))
    });
  }





  }

about.ts

import { Component } from '@angular/core'; 
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import {DataApi} from '../../app/shared/shared';
import {Http, HttpModule} from '@angular/http';


import  {TeamsPage} from '../teams/teams';

 @IonicPage()
 @Component({
 selector: 'page-about',
 templateUrl: 'about.html',
  })
 export class AboutPage {

 names: any;
 constructor(public navCtrl: NavController, public navParams: NavParams, 
 public dataApi:DataApi, public http:Http) {

 }

 item(){
    this.navCtrl.push(TeamsPage);
  }

 ionViewDidLoad(){
    this.dataApi.getAdress().then(data => this.names= data[0]);
    console.log("willloaded");


   }


}

about.html

   <ion-header>

   <ion-navbar>
   <ion-title>Select Tournament </ion-title>
   </ion-navbar>

   </ion-header>


  <ion-content>
     <ion-list>    
       <button ion-item *ngFor="let item of names" (click)="item()">
         <h2> {{item.name}}</h2>
       </button>
     </ion-list>

 </ion-content>

data.json

 [
 [
{
  "id": 15,
  "name": "Sahne Sistemleri",
  "image": "sahne/1.jpg",

   {

     "image": "sahne/1.jpg"
   }

},
{
  "id": 16,
  "name": "Görüntü Sistemleri",
  "image": "sahne1/1.jpg"
},
{
  "id": 17,
  "name": "Podyum Sistemleri",
  "image": "sahne2/1.jpg"
},
{
  "id": 18,
  "name": "Masa, Sandalye ve Loca Grupları",
  "image": "sahne3/1.jpg"
},
{
  "id": 19,
  "name": "Çadır Sistemleri",
  "image": "sahne4/1.jpg"
},
{
  "id": 20,
  "name": "Mobil Jenaratör Hizmetleri",
  "image": "sahne5/1.jpg"
},
{
  "id": 21,
  "name": "Simultane(Çeviri) Sistemleri",
  "image": "sahne6/1.jpg"
}
]
]

aboutpage

enter image description here

点击其中一项

teampage enter image description here

2 个答案:

答案 0 :(得分:4)

由于TeamsPage是IonicPage,因此它是延迟加载的。

检查IonicPage。 避免在其他页面中导入TeamsPage。为了推送页面, 使用相当于页面的字符串。 例如:

item(){
    this.navCtrl.push('TeamsPage');
  }

并删除导入。

如果您想使用自定义字符串,请在TeamsPage的装饰器中进行设置。

@IonicPage({
  name:'teams-page'
})

在推送页面时,

   item(){
        this.navCtrl.push('teams-page');
      }

其次,您的函数名item()似乎与您的for循环变量item冲突。 将其更改为:

   <button ion-item *ngFor="let n of names" (click)="item()">
      <h2> {{n.name}}</h2>
   </button>

答案 1 :(得分:3)

只需在HTML内更改方法名称就很容易,因为在* ngFor迭代器中,您使用了相同的循环名和方法名..!

 <button ion-item *ngFor="let **item** of names" (click)="**item**()">
     <h2> {{item.name}}</h2>
   </button>