Angular 2. @Input is not recognized as a valid property

Within my parent component, I have the following template:

<ion-content>
  <blocks-banners-slideshow class="contentBlock" [config]="{ zone: 'mobile'}" [config_private]="{ url: 'url'}" [slideOptions]="{ loop: true, pager: true}"></blocks-banners-slideshow>
  <blocks-catalog-category class="contentBlock" [config]="{ parent_id: 0 }" [config_private]="{ url: 'url'}"></blocks-catalog-category>
  <blocks-catalog-topproducts class="contentBlock" [config]="{ filter: { dir: 204}, page: 1, pageSize: 8}" [config_private]="{ url: 'url', showMoreProducts: false, columns: { tablet: 4, phone: 2}}"></blocks-catalog-topproducts>
</ion-content>

However, when the application attempts to display it, I encounter the following error:

Unhandled Promise rejection:

Template parse errors:

Can't bind to 'config_private' since it isn't a known property of 'blocks-banners-slideshow'.
1. If 'blocks-banners-slideshow' is an Angular component and it has 'config_private' input, then verify that it is part of this module.
2. If 'blocks-banners-slideshow' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schemas' of this component to suppress this message.

The child component details are as follows:

@Component({
  selector: 'blocks-banners-slideshow', //Selector
  templateUrl: '/mobilesiteapp/template/?path=pages/banners/blocks/slideshow', //Template
})

export class BannersBlocksSlideShow extends AbstractBlock{
  list: Array<BannerItem>;
  mySlideOptions: any;

  //Input data
  @Input() config: any;
  @Input() config_public: any;
  @Input() slideOptions = {};

 ....
}

Any suggestions on how to resolve this issue?

Answer №1

Encountered an error: Cannot bind to 'config_private' as it is not a recognized property of 'blocks-banners-slideshow'.

This error indicates that the config_private property cannot be found, and there are three possible solutions:

  1. Add the missing property to the component
  2. In the component, change the property from config_public to config_private
  3. In the HTML file, change the bound property from config_private to config_public

First Solution - Add the missing property to the component

@Component({
  selector: 'blocks-banners-slideshow', // Selector
  templateUrl: '/mobilesiteapp/template/?path=pages/banners/blocks/slideshow', // Template
})

export class BannersBlocksSlideShow extends AbstractBlock{
  list: Array<BannerItem>;
  mySlideOptions: any;

  // Input data
  @Input() config: any;
  @Input() config_public: any;
  @Input() config_private: any; // <--- Add this
  @Input() slideOptions = {};

 ....
}


Second Solution - In the component, change the property from config_public to config_private

<ion-content>
  <blocks-banners-slideshow class="contentBlock" [config]="{ zone: 'mobile'}" [config_private]="{ url: 'url'}" [slideOptions]="{ loop: true, pager: true}"></blocks-banners-slideshow>
  <blocks-catalog-category class="contentBlock" [config]="{ parent_id: 0 }" [config_private]="{ url: 'url'}"></blocks-catalog-category>
  <blocks-catalog-topproducts class="contentBlock" [config]="{ filter: { dir: 204}, page: 1, pageSize: 8}" [config_private]="{ url: 'url', showMoreProducts: false, columns: { tablet: 4, phone: 2}}"></blocks-catalog-topproducts>
</ion-content>

Since [config_public]="..." is not being used for binding, consider changing config_public to config_private in your component

@Component({
  selector: 'blocks-banners-slideshow', // Selector
  templateUrl: '/mobilesiteapp/template/?path=pages/banners/blocks/slideshow', // Template
})

export class BannersBlocksSlideShow extends AbstractBlock{
  list: Array<BannerItem>;
  mySlideOptions: any;

  // Input data
  @Input() config: any;
  @Input() config_private: any; // <--- Change this
  @Input() slideOptions = {};

 ........
}


Third Solution - In the HTML file, change the bound property from config_private to config_public

Try updating the bound property to config_public

<ion-content>
  <blocks-banners-slideshow class="contentBlock" [config]="{ zone: 'mobile'}" [config_public]="{ url: 'url'}" [slideOptions]="{ loop: true, pager: true}"></blocks-banners-slideshow>
  <blocks-catalog-category class="contentBlock" [config]="{ parent_id: 0 }" [config_public]="{ url: 'url'}"></blocks-catalog-category>
  <blocks-catalog-topproducts class="contentBlock" [config]="{ filter: { dir: 204}, page: 1, pageSize: 8}" [config_public]="{ url: 'url', showMoreProducts: false, columns: { tablet: 4, phone: 2}}"></blocks-catalog-topproducts>
</ion-content>

Update

Ensure that the component is declared in the app's module

app.module.ts

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';

import { AppComponent } from './app.component';

import { BannersBlocksSlideShow } from './banners-blocks-slideShow/banners-blocks-slideShow.component';


@NgModule({
    imports: [
        BrowserModule
    ],
    declarations: [
        AppComponent,
        BannersBlocksSlideShow
    ],
    providers: [],
    bootstrap: [AppComponent],
})
export class AppModule { }

Answer №2

The reason behind the issue I faced was due to my use of

@Param

rather than

@Param()

prior to declaring the attribute.

Answer №3

When utilizing lazy loading in Ionic 2, it is important to remember to declare your block in the page module. Failure to do so can result in the same error occurring.

Answer №4

Expanding on the insights shared by Alexander Zakusilo, I encountered a similar issue that took some time to resonate with me...

An informative post on Stack Overflow sheds light on lazy loading in Ionic 3 and provides valuable links to documentation...

Consider having multiple components grouped within a component module.

const components = [
  GraphLineComponent,
  GraphDateRangeTabsComponent,
  GraphBarComponent,
];

@NgModule({
    declarations: [
    ...components,
  ],
  imports: [IonicModule],
    exports: [
    ...components,
  ]
})
export class ComponentsModule {}

If you intend to utilize these components in a lazily loaded Ionic page, it is essential to import your components module into the respective page module.

@NgModule({
  declarations: [
    GraphPage,
  ],
  imports: [
    IonicPageModule.forChild(GraphPage),
    ComponentsModule,
  ],
})
export class GraphPageModule {}

The mistake I made was importing the components module into my bootstrapped app module and anticipating seamless functionality. However, without lazy loading, this approach will work as all components exist within the app module.

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

Send a pair of selected options from dropdown menus to a service using Angular

I have created a component that needs to pass two values from two separate dropdowns to my service on button click. Here is the code for my component: import { Component, Input, OnInit } from '@angular/core'; import { CategoryType } from '. ...

Is it possible to use a single type predicate for multiple variables in order to achieve type inference?

Is there a way to optimize the repeated calls in this code snippet by applying a map to a type predicate so that TSC can still recognize A and B as iterables (which Sets are)? if(isSet(A) && isSet(B)) { ...

Sending every piece of information to the URL may not be the most efficient approach, in my opinion

Lately, I have incorporated NodeJS into my Angular project and here is how I am currently implementing it: Node : app.get('/register/:username/:password', function(req, res){ db.collection('users').insertOne({ username: req ...

Error message in TypeScript class extension: "TypeError: Object.setPrototypeOf expects an object or null, received undefined."

In my Ionic 3 application, I have the following code snippets: @Injectable() // I also tried without @Injectable and encountered the same error export class M_someClass { constructor () { } method1 () { console.log("method1 used") } } @Injectabl ...

Error: The specified property is not found in type 'never' - occurring with the ngFor loop variable

When working with API responses and dynamically sorting my view, I utilize an ngFor loop. Here's the snippet of code in question: <agm-marker *ngFor="let httpResponses of response" [latitude]= "httpResponses.lat" [longitude]=& ...

Splitting code efficiently using TypeScript and Webpack

Exploring the potential of webpack's code splitting feature to create separate bundles for my TypeScript app has been a priority. After scouring the web for solutions, I stumbled upon a possible lead here: https://github.com/TypeStrong/ts-loader/blob/ ...

What events can cause all store states to be loaded when the page is altered?

I am currently utilizing ngrx/store, ngrx/effects, and ngrx/router. The implementation of my effects is structured as follows: @Effect() loadOneProduct$ = this.updates$ .whenAction(LOAD_ONE_PRODUCT) .switchMap(() => this.productService.loadOn ...

Display of Navigation Bar in Angular is Not Proper

Currently diving into the world of Angular, I've encountered an issue with a material menu that isn't displaying correctly. The expected outcome based on my code should resemble this image: https://i.stack.imgur.com/z70Aq.png This snippet showc ...

Is it advisable to relocate TypeScript declarations to their own file?

My code file is getting too long with both declarations and other code mixed together. Below is a snippet from my ./src/index.ts file: // --> I want to move this to a separate file export interface Client extends Options { transactionsCounter: num ...

Configuring eslint-import-resolver-typescript in a multi-package repository

I'm currently working on implementing path-mapping within a monorepo structure. Despite having existing eslint-plugin-import rules in place, I am encountering an error stating "Unable to resolve path to module" for all mapped imports. app/ ├─ pack ...

Angular isn't generating a new project

I am having some trouble creating an Angular project successfully. F:\Demos>npm init F:\Demos>npm install @angular/cli The above two commands went smoothly. However, when I tried to execute the following command: F:\Demos>ng new m ...

Filtering a list of invoices to find those including a "TV" item within its nested item list can be achieved efficiently using TypeScript

I am working with an array of "Invoices" objects that contain a nested array of "Items". Here is an example: [ { "invoiceNo":"10", "customerId":"101", "invoiceTotal":"2500", "items":[ { "itemId":"1", ...

Handle and manage errors within the controller in Express.js to prevent the further execution of asynchronous functions

Consider a scenario where there is an API endpoint /register, designed to register new users in an application. The function utilized is asynchronous, as an attempt is made to incorporate an asynchronous process within an AuthController when performing pas ...

Encountered issues while trying to utilize wasm function within Vue framework

When attempting to integrate wasm with Vue, I encountered a frustrating issue where the startQuorum function in my wasm file could not be located. import { Go } from './wasm_exec' import quorumWasmUrl from './lib.wasm' export const sta ...

What steps can be taken to ensure the WhatsApp icon is easily visible on a small screen?

I currently have a navigation bar with the left side dedicated to navigation items and the right side featuring a whatsapp icon. <mat-toolbar class="nav"> <a routerLink="app-aaa" mat-button>aaa</a> <a routerLi ...

Managing JSON object with irregular data in Angular 7: Best Practices

When the service returns data in a specific format, I am able to view the data in the developer tools. {"results":{"BindGridDatatable":[{"ID":"0005","Name":"Rohit"}, {"ID":"0006","Name":"Rahul"}], "Totalvalue":119}} ...

Incorporating Interpolation into Angular 2 Routing

I have a dropdown menu for selecting categories, and based on the selected category, I want to update the router link for the menus. For example, if I select Category1, then the router link for SubMenu1 should be BASE/category1/submenu1. Similarly, for Cat ...

Saving only the final item, a Json Array of Objects does not retain all of

I am facing an issue where I need to define an array of objects and store multiple objects within it. However, I can only add one object to the array (the last object) and cannot add more objects to it. Inside the Dataservice class getData(){ return this ...

Angular 5 - Empty array containing objects has a length of zero

In my app.component.ts file, I have an array initialized to load objects in the onInit event: ngOnInit() { this.pages = []; } Within the ngOnInit event, I also have a setInterval method that evaluates an expression every few milliseconds: setInterval(() ...

Halting external observation using switchmap without finishing internal observations

After conducting a thorough search, I couldn't find a similar question to mine, so I apologize if this has been asked before. In my scenario, I have multiple connected observables working in sequence. One of the observables, let's call it Obser ...