TypeError:v.context。$ implicit不是函数 [英] TypeError: v.context.$implicit is not a function

查看:270
本文介绍了TypeError:v.context。$ implicit不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm new to Typescript.It has been 3 days.I want to access the data from Firebase.And I access and list. I get an error when I want to pass to another page with (Click) ="item ()".Where am I doing wrong.

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

aboutpage

<啊ref =https://i.stack.imgur.com/epcu2.png =nofollow noreferrer>

点击其中一个项目

teampage

推荐答案

TeamsPage 是一个IonicPage,它是延迟加载的。

Since TeamsPage is an IonicPage, it is lazyloaded.

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

Check IonicPage. Avoid importing TeamsPage in other pages. In order to push the page, use the string equivalent of the page. eg:

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

并删除导入。

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

Or if you want to use a custom string, set it in decorator in TeamsPage.

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

在推送页面时,

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

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

Secondly, your function name item() seems to clash with your for loop variable item. Change it to:

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

这篇关于TypeError:v.context。$ implicit不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆