The error message indicates that the property `v.context.$implicit` is not callable

I am a beginner with Typescript and it has only been 3 days. I am trying to access data from Firebase and display it in a list. However, I keep encountering an error when trying to navigate to another page using (Click) ="item ()". Can someone point out where I might be going 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": "Stage Systems",
"image": "stage/1.jpg",

{

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

},
{
"id": 16,
"name": "Visual Systems",
"image": "stage1/1.jpg"
},
{
"id": 17,
"name": "Podium Systems",
"image": "stage2/1.jpg"
},
{
"id": 18,
"name": "Table, Chair and Loge Groups",
"image": "stage3/1.jpg"
},
{
"id": 19,
"name": "Tent Systems",
"image": "stage4/1.jpg"
},
{
"id": 20,
"name": "Mobile Generator Services",
"image": "stage5/1.jpg"
},
{
"id": 21,
"name": "Simultaneous(Translation) Systems",
"image": "stage6/1.jpg"
}
]
]

About Page

https://i.sstatic.net/epcu2.png

Click on one of the items

Team Page https://i.sstatic.net/QoVxT.png

Answer №1

When TeamsPage is defined as an IonicPage, it will be lazyloaded.

To learn more about this, visit the IonicPage documentation. It's best practice to avoid importing TeamsPage in other pages. Instead, when pushing the page, use the string equivalent of the page name. For example:

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

You can also set a custom string for the page by using a decorator in TeamsPage.

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

Make sure to push the page using the new custom string:

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

Additionally, consider renaming your function from item() to prevent conflicts with your loop variable named item:

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

Answer №2

Simply modify the name of your function in the HTML code because you have used the same loop name and method name in your *ngFor iterator..!

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

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The component is not responding to list scrolling

Issue with Scroll Functionality in Generic List Component On the main page: <ion-header> <app-generic-menu [leftMenu]="'left-menu'" [rightMenu]="'client-menu'" [isSelectionMode]="isSelectio ...

In React TS, the function Window.webkitRequestAnimationFrame is not supported

I'm facing an issue where React TS is throwing an error for window.webkitRequestAnimationFrame and window.mozRequestAnimationFrame, assuming that I meant 'requestAnimationFrame'. Any suggestions on what to replace it with? App.tsx import Re ...

Bring in TypeScript property from an external scope into the current scope

I am encountering an issue with my TypeScript code. Inside the anonymous functions, I am unable to change the properties of the class because they are out of scope. Is there a way to pass them in so that they can be modified? class PositionCtrl { ...

Developing Angular components with nested routes and navigation menu

I have a unique application structure with different modules: /app /core /admin /authentication /wst The admin module is quite complex, featuring a sidebar, while the authentication module is simple with just a login screen. I want to dyn ...

Issue: Module '@nrwl/workspace/src/utilities/perf-logging' not found

I attempted to run an Angular project using nxMonorepo and made sure to install all the necessary node modules. However, when I tried running the command "nx migrate --run-migrations" in my directory PS C:\Users\Dell\Desktop\MEANAPP&bso ...

Updating the state of a nested array using React Hooks

After spending some time working with React Hooks, my main struggle has been dealing with arrays. Currently, I am developing a registration form for teams. Each team consists of a list of players (an array of strings). The goal is to allow users to add t ...

What are the benefits of sharing source files for TypeScript node modules?

Why do some TypeScript node modules, like those in the loopback-next/packages repository, include their source files along with the module? Is there a specific purpose for this practice or is it simply adding unnecessary bulk to the module's size? ...

Leveraging a Derived-Class Object Within the Base-Class to Invoke a Base-Class Function with Derived-Class Information

I have a situation where I need to access a method from a derived class in my base generic component that returns data specific to the derived class. The first issue I encountered is that I am unable to define the method as static in the abstract class! ...

Eliminate properties from a TypeScript interface object

After receiving a JSON response and storing it in MongoDB, I noticed that unnecessary fields are also being stored in the database. Is there a way to remove these unnecessary fields? interface Test{ name:string }; const temp :Test = JSON.parse('{ ...

Setting a value in the selectpicker of rsuitejs involves assigning a specific value to the

const _DATA = [{ code: 'code1', name: 'Jagger' },{ code: 'code2', name: 'Tigger' },{ code: 'code3', name: 'Lion' }] <SelectPicker data={_DATA.map(x => {return {label: x.n ...

Creating a library that relies on Cypress without the need to actually install Cypress

We have adopted the page object pattern in our testing and recently made the decision to move them into a separate npm-published library for reusability. Considering the heavy nature of Cypress and potential version conflicts, we believe it's best no ...

The request to search for "aq" on localhost at port 8100 using Ionic 2 resulted in a 404 error, indicating that the

Trying to create a basic app that utilizes an http request, but facing challenges with cors in ionic 2. To begin with, modifications were made to the ionic.config.json { "name": "weatherapp", "app_id": "", "v2": true, "typescript": true, "prox ...

Authentication of users using NextJS Dashboard App API

I am currently following this tutorial, but instead of fetching data via a PostgreSQL request, I want to utilize an API. When I call an async function with await, it initially returns undefined and then the user object after receiving a response from the ...

Utilizing Jest and nest.js for testing with absolute paths

Looking at my jest configuration inside the package.json: "jest": { "moduleFileExtensions": [ "js", "json", "ts" ], "moduleDirectories":["node_modules", "src" ...

When {} = {} is utilized in an Angular constructor, what is its function?

While going through an Angular dynamic forms tutorial, I came across this code snippet and got confused by the {} = {} in the constructor. Here is the complete snippet: export class QuestionBase<T> { value: T; key: string; label: string; re ...

Struggle with implementing enums correctly in ngSwitch

Within my application, I have implemented three buttons that each display a different list. To control which list is presented using Angular's ngSwitch, I decided to incorporate enums. However, I encountered an error in the process. The TypeScript co ...

Derive the property type based on the type of another property in TypeScript

interface customFeatureType<Properties=any, State=any> { defaultState: State; properties: Properties; analyzeState: (properties: Properties, state: State) => any; } const customFeatureComponent: customFeatureType = { defaultState: { lastN ...

Utilize a fresh function in Angular to retrieve and store data from a URL into a variable

Currently, I am attempting to utilize Angular in order to retrieve data from a link upon clicking a button. As a newcomer to Angular with only 2 days experience, my knowledge is quite limited. What I aim to achieve is triggering the loading of JSON data w ...

Error: Gulp is using ts-node and returning 'void' instead of 'Task', but it cannot find the type 'Task'

Seeking assistance from experienced individuals in the realm of gulp.js and typescript - could someone provide guidance for a struggling newcomer? I am currently utilizing the most recent versions of all relevant tools (node, ts-node, gulp, ts, @types/gul ...

Converting a string[] to an EventEmitter string[] in Angular 4 with TypeScript: Step-by-step guide

Programming Language: Typescript – written as .ts files Development Framework: Angular 4 I'm currently working on an application that is supposed to add chips (similar to tags in Angular 1) whenever a user types something into the input box and hi ...