typescript - TypeError : v. context.$implicit 不是函数

标签 typescript ionic2

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

data-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"
}
]
]

关于页面

enter image description here

点击其中一项

模板 enter image description here

最佳答案

因为 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>

关于typescript - TypeError : v. context.$implicit 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43501592/

相关文章:

javascript - 在 MobileFirst 8 的 JS HTTP 适配器中添加参数

html - 如何针对不同的宽度和高度响应地调整元素

css - ionic 2 : How to overwrite the style of ionic component

angular - ng-pick-datetime 日期选择器格式

angular - 在 ionic3 中延迟加载,但错误 : No component factory found

typescript - 在 <ion-content> 中获取 Canvas 的初始高度/宽度

ios - 如何修复 ionic 2 Apple Mach-O Linker 错误?

typescript - 使用 jsPDF rtl 支持的 Html 到 pdf

javascript - 具有很少角色访问权限的 Angular JWT

Angular 2/Ionic 2 TypeError : zxcvbn_1. 默认不是函数