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

TypeScript encounters a problem when attempting to concatenate arrays with different signature overloads

I encountered the following error message: There is an issue with overloading. Overload 1 of 2, '(...items: ConcatArray<{ title: string; width: number; dataIndex: string; render: (level: string) => Element; }>[]): { title: string; width: nu ...

Developing a type specifically for this function to operate on tuples of varying lengths

I am currently developing a parser combinator library and I am in need of creating a map function that can take N parsers in a tuple, along with a function that operates on those N arguments and returns a parser that parses into the return type specified b ...

I'm puzzled as to why I have to encode the path parameter twice in order for the REST call to properly handle special characters

I have a challenge with a REST call that fetches a product's ingredients using the product name as the path variable. I allow for any character to be used, and I know I need to use encodeURIComponent(name) to encode characters such as "/" to prevent m ...

Tips for managing nested data in Angular 4 using a Bootstrap 4 data-table

I am currently using the Data Table from a GitHub project found at: https://github.com/afermon/angular-4-data-table-bootstrap-4-demo. It works perfectly with data structured in a key-value format like the sample provided. However, I am facing challenges wh ...

Discovering Virtual Directories within IIS using port 4200 in Angular

Having configured an IIS virtual directory with various photos, I am facing difficulty accessing it from my Angular App. A 404 NOT FOUND error is displayed when trying to access the directory. On the other hand, I can successfully access the folder using a ...

Issue with implicitly assigning 'any' type to overloaded variadic generic function

We have some code snippets for you to review: export type actions = { abort: () => void; back: () => void; next: () => void; resume: () => void; }; class Sabar { public use<T1>(fn: (arg1: T1, ctx: object, actions: actions) =&g ...

Step-by-step guide on adding a gallery image in Node.js

I need help with posting my gallery image to a nodeJs server. Here is the code I am currently using: vm.getImageSaveContactInst = function() { var options = { maximumImagesCount: 1, // Only selecting one image for this example width ...

Determine in React whether a JSX Element is a descendant of a specific class

I am currently working with TypeScript and need to determine if a JSX.Element instance is a subclass of another React component. For instance, if I have a Vehicle component and a Car component that extends it, then when given a JSX.Element generated from ...

Steps to validate the execution of the ngCopy function in an Angular 6 unit test

While working on one of my angular components, I have implemented the ngCopy module to enable text copying to clipboard. The code snippet below showcases how I have used this module: import {Component, Input, OnInit} from '@angular/core'; import ...

The EventEmitter in Angular 8 is prohibiting the emission of an Object

Is there a way I can emit an Object instead of primitive data types? I have an object const amount = { currenty: 'USD', total: '10.25' }; that I need to emit to the parent component. export class MyChildComponent implements OnInit { ...

Run a Nest.JS Kafka microservice while continuing to listen on port 3000

I have a Nest.JS microservice set up as follows: const app = await NestFactory.createMicroservice<MicroserviceOptions>(AppModule, { transport: Transport.KAFKA, options: { client: { brokers: ['localhost:9092'], } } }); aw ...

Having trouble with unit testing a subscription within the ngOnInit lifecycle hook

I subscribed to an observable in the ngOnInit method, but when I try to write a test for it, it doesn't seem to be working. Below is the class I am attempting to test: ngOnInit() { this.myService.updates$.pipe(takeUntil(unsusbribe$)) .subscribe ...

What is the process for accessing a different view and its features on a separate screen using Angular portal?

In my angular project, I have multiple components. One component is being looped with an array using the following code: <body-chart *ngFor="..."></body-chart> Within the body-chart component : <div> <canvas id="canv ...

What Causes CORS Errors When Sending Encoded Information?

Dealing with poor data quality is a challenge I face. An example of this is when the primary key value of a table contains spaces and special characters, like 35581/H0034-100003 My goal is to retrieve a record by its primary key value using a GET request ...

The URL dynamically updates as the Angular application loads on GitHub Pages

Encountering an unusual issue when trying to access my angular website on GitHub pages. The URL unexpectedly changes upon opening the page. Please check it out at this link: The original expected URL should be However, as the page loads, the URL gets alt ...

Error: TypeScript is unable to locate the 'moment' module

My TypeScript React application was set up using npx create-react-app --template typescript. However, when I try to start the app with npm start, I encounter an error in one of my files: TypeScript error in /<path>/App.tsx: Cannot find module ' ...

The theming feature in Angular 5 with Bootstrap 4 and Bootswatch seems to be malfunctioning

Having trouble implementing bootswatch themes with angular 5 and bootstrap 4? I've added the following to styles.scss: @import "~bootswatch/dist/cerulean/variables"; @import "~bootstrap/scss/bootstrap"; @import "~bootswatch/dist/cerulean/ ...

Issue with Dynamic Theming in Ionic Framework

Currently, I am using Ionic in combination with Angular to create an App. I have introduced dynamic theming by adding two .scss files into my theme folder. In my app.scss file, I define the layout of components without colors, while all color styles are st ...

Unleashing the power of joint queries in Sequelize

Project.data.ts import { DataTypes, Model, CreationOptional, InferCreationAttributes, InferAttributes, BelongsToManyGetAssociationsMixin, BelongsToManySetAssociationsMixin, BelongsToManyAddAssociationsMixin } from 'sequelize'; import sequelize fr ...

Exploring the functionalities of can-deactivate without incorporating routing

I'm facing an issue with a parent component and multiple child components. The parent component contains a form, while each child component also has its own form. Unfortunately, all child components share the same route as the parent component and hav ...