Ionic - What is the correct way to import ViewController? - Uncaught (in promise): Error: ViewController provider not found

I have a Popover in my app and I want it to behave differently based on the selected item. I followed the instructions in the Ionic documentation to achieve this.

 Error: Uncaught (in promise): Error: No provider for ViewController!

When I tried adding ViewController to app.module.ts, I received the following error:

Uncaught Error: Can't resolve all parameters for ViewController: (?, ?, ?)

Question: How can I properly import ViewController?

Here is the code for the popover component:

import { Component } from '@angular/core';
import { ViewController } from 'ionic-angular';

@Component({
  selector: 'popover',
  templateUrl: 'popover.html'
})
export class PopoverComponent {

  popoverItemList = [{name: 'Create Event'}, {name: 'Event Overview'}];

  selectedTitle: string;

  constructor(private viewCtrl: ViewController) {
    this.selectedTitle = "";
  }

  setSelectedTitle(selectedItem) {
   this.selectedTitle = selectedItem;
    this.viewCtrl.dismiss(this.selectedTitle);
  }

}

The popover is called like this:

presentPopover(ev) {
   let popover = this.popoverCtrl.create(PopoverComponent, {
   });
   popover.present({
     ev: ev
   });

   popover.onDidDismiss((popoverData) => {
      if(popoverData === 'Create Event') {
        this.navCtrl.push(CreateEventPage, {

        });
      } else if(popoverData === 'Event Overview') {
        this.navCtrl.push(EventlistPage, {

        });
      }
    })

Answer №1

Using { ViewChild } from '@angular/core' and { ViewController } from 'ionic-angular'

The ViewController is not declared in the Constructor, but instead using @ViewChild(ViewController) view: ViewController

Answer №2

const { DialogController } =  require('@ionic/react');
let handleClose = () => {
viewCtrl.close();
}

Answer №3

import { Component } from '@angular/core';
import { ViewController } from 'ionic-angular';

@Component({
  selector: 'custom-popover',
  templateUrl: 'custom-popover.html',
  providers : [ViewController] //included for functionality
})
export class CustomPopoverComponent {

  popoverItems = [{name: 'Create Event'}, {name: 'Event Overview'}];

  selectedTitle: string;

  constructor(private viewCtrl: ViewController) {
    this.selectedTitle = "";
  }

  setSelectedTitle(selectedItem) {
   this.selectedTitle = selectedItem;
    this.viewCtrl.dismiss(this.selectedTitle);
  }

}

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

Angular's AuthGuard function will automatically trigger a session timeout if the user remains idle

Currently in the application, users can only access certain routes if they are authenticated. This is controlled by the canActivate function in the AuthGuard. However, I want to implement a session timeout feature that automatically logs out the user aft ...

Addressing ESLint and TypeScript Issues in Vue.js with Pinia: A comprehensive guide

Experiencing difficulties with Vue.js + Pinia and need assistance to resolve these issues. Error: 'state:' is defined but never used. Here is the snippet of code located in @/stores/user.ts. import { defineStore } from 'pinia' export ...

Using NgFor to duplicate a div containing a form and link the inputs to NgModel

Working on a form using Angular to store datasets with inputs for name and description. Users can add multiple datasets by clicking the "Add" button. To achieve this, I initialized a dataset list with one element in app.component.ts. Using NgFor, it dynam ...

Delay the Ngrx effect by 2 seconds before initiating the redirect

I have an ngrx effect that involves calling an HTTP method and then waiting for 2 seconds before redirecting to another page. However, the current behavior is that it redirects immediately without waiting. confirmRegistration$ = createEffect(() => { ...

Typescript void negation: requiring functions to not return void

How can I ensure a function always returns a value in TypeScript? Due to the fact that void is a subtype of any, I haven't been able to find any generics that successfully exclude void from any. My current workaround looks like this: type NotVoid ...

Error message: Unable to assign type (Combining React, Typescript, and Firebase)

Just started using TypeScript and in the process of migrating my React app to incorporate it. Encountering some type issues with Firebase auth service that I can't seem to find a solution for. Any suggestions? import React, { useEffect, useState } f ...

Show a Toast in React without relying on useEffect to manage the state

I have successfully implemented the Toast functionality from react-bootstrap into my application using the provided code. However, I am unsure if it is necessary to utilize useEffect to set show with setShow(items.length > 0);. Would it be simpler to ...

utilizing tabview for component replacement

Having trouble changing components in Angular 7 with PrimeNG tabview tabs? Need some assistance? I have a setup with 3 components, and I want to switch between them when clicking on the panel inside the tabview. I've tried using onchange functions i ...

Tips for ensuring that jQuery runs in the correct order within Angular 2

As a beginner with Angular 2 and asynchronous loading, I have encountered some difficulties in finding the right approach for running jQuery scripts in the correct sequence within an Angular 2 project. Despite exploring various resources such as: How to u ...

Ensuring Completion of Operations before Executing Observables in Angular 2

Working with observables has been a bit of a learning curve for me, especially when integrating Firebase. It seems like there's quite a bit of complexity involved in order to achieve the desired results! Currently, I'm facing an issue where my ob ...

Substitute a specific text within an array of strings using Angular 2

Currently, I am working with a string array that includes elements such as age, gender, and nationality. Specifically, I am interested in replacing the element "age" with "agexxxx". Do you know of any methods to accomplish this within an Angular framewor ...

The Perplexing Problem with Angular 15's Routing Module

After upgrading to Angular 15, I encountered an issue with the redirect functionality. The error message points out a double slash "//" in my code, but upon inspection, I couldn't find any such occurrence. * * PagesRoutingModule: const routes: Routes ...

Organize routes into distinct modules in Angular 6

Currently grappling with routing in my Angular 6 application. Wondering if the structure I have in mind is feasible. Here's what it looks like: The App module contains the main routing with a parent route defining the layout: const routes: Routes = ...

Exploring Observable Functionality in Angular 6

I've been grappling with understanding Angular Observables, but I've managed to get it working. My goal is to fetch data for my dynamic navigation bar. I successfully verified whether the user is logged in or not and displayed the Login or Logout ...

I am experiencing issues with arrow pagination not functioning properly in TypeScript

My current project involves building a customer table with 10 customers displayed on each page. Additionally, there are arrows below the table to help users navigate and view more customers. Unfortunately, there seems to be an issue with the functionality ...

Am I utilizing Angular's signals correctly? And what is the purpose of still requiring ChangeDetectorRef.detectChanges()?

I have been experimenting with signals and I am questioning whether the current use case would be more beneficial without using Signals and instead just having a "normal" class member swiper?: Swiper: @Component({ selector: '[app-test]', stan ...

Exploring TypeScript's Index Types: Introduction to Enforcing Constraints on T[K]

In typescript, we can utilize index types to perform operations on specific properties: interface Sample { title: string; creationDate: Date; } function manipulateProperty<T, K extends keyof T>(obj: T, propName: K): void { obj[propName] ...

Combining Angular, Node.js, and Spring Boot Java REST API to enable Angular Universal functionality

I am seeking guidance on integrating Angular with NodeJS and Spring Boot for my application. Currently, I have built a system that utilizes Angular for the frontend and Java/Spring Boot for the backend REST API. However, I have come across challenges with ...

The code encountered an issue with TS2554 error, as it was anticipating two arguments but was only provided with one when

Before, I utilized ViewChild like this: @ViewChild("InternalMedia") localStream; @ViewChild("emoji") mEmoji; Everything was functioning well up until angular-7.x. However, after updating to angular-8.x, the following error started popping up: .../call_ ...

The promise catch method does not handle JSON parsing correctly

Utilizing Angular's Http to interact with my API has been successful for handling responses with a status of 200. The data is parsed correctly and outputted as expected within the first .then() block. However, when encountering an error with a status ...