【问题标题】:TypeError: v.context.$implicit is not a functionTypeError: v.context.$implicit 不是函数
【发布时间】:2017-09-16 00:42:07
【问题描述】:

我是 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"
}
]
]

关于页面

点击其中一项

团队页面

【问题讨论】:

  • TeamsPage 也是 IonicPage 吗?
  • 是的,IonicPage @suraj

标签: typescript ionic2


【解决方案1】:

由于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>

【讨论】:

  • 我做了这样一段话。我的问题还在继续。当您从 About.html 中删除 ngFor 时,它可以工作,NgFor 有问题吗?我真的不明白问题是什么?
  • 更改函数名.. 你的循环项和函数名必须冲突
【解决方案2】:

您只需在 HTML 中更改您的方法名称非常简单,因为在您的 *ngFor 迭代器中您使用了相同的循环名称和方法名称 ..!

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

【讨论】:

    猜你喜欢
    • 2018-04-11
    • 2017-04-07
    • 2020-06-29
    • 2020-06-17
    • 1970-01-01
    • 1970-01-01
    • 2020-03-03
    • 2021-06-05
    • 2019-10-03
    相关资源
    最近更新 更多