the input parameter is not being passed to the component

I need assistance with creating an inline input edit component.

The component is loading correctly, but it seems like the @Input() variables are always returning undefined.

index.html

...
<app-inlineinput
            [name]="username"
            [fieldValue]="myname"
            [isRequired]="true"
            (updateValue)="saveField('username', $event)"></app-inlineinput>
...

inlineinput.component.ts

    import { Component, OnInit } from '@angular/core';
    import { Input, EventEmitter, Output, ViewChild, Renderer } from '@angular/core';

    @Component({
      selector: 'app-inlineinput',
      templateUrl: './inlineinput.component.html',
      styleUrls: ['./inlineinput.component.scss'],
    })
    export class InlineinputComponent implements OnInit {

      @Input() name:string;
      @Input() fieldValue:string;
      @Input() isRequired:string;
      @Input() minLength:string;
      @Input() maxLength:string;

      @Output() updateValue: EventEmitter<any> = new EventEmitter();

      @ViewChild('container') container;

      public value:any;
      public isEditView:boolean = false;
      public docEditUnlisten:any;

      constructor(
                  private renderer:Renderer
                  ) { }

      ngOnInit(){
        console.log(this.fieldValue);      <============ THIS SHOWS UNDEFINED
      }

      showEditable()
      {
        this.value = this.fieldValue;
        this.isEditView = true;

        this.docEditUnlisten = this.renderer.listenGlobal('document', 'click', (event) => {
          if(!this.container.nativeElement.contains(event.target)){
            this.showDetail();
          }
        });
      }

      save(){
        this.updateValue.emit(this.value);
      }

      showDetail(){
        this.isEditView = false;
      }

    }

inlineinput.component.module.ts

    import { NgModule } from '@angular/core';
    import { FormsModule } from '@angular/forms';
    import { CommonModule } from '@angular/common';
    import { IonicModule } from '@ionic/angular';

    import { InlineinputComponent } from './inlineinput.component';

    @NgModule({
      imports: [
        CommonModule,
        FormsModule,
      ],
      declarations: [
        InlineinputComponent
      ],
      exports: [
        InlineinputComponent
      ],
      entryComponents: [
      ],
    })
    export class InlineinputComponentModule {
    }

inlineinput.component.html

    ...
    <span class="editable-click">
      => {{fieldValue}}
      <div #container class="editable-container editable-inline">
      ...

I'm attempting to display => {{fieldValue}}, but it's empty and even in the component's ngOnInit, it shows as undefined.

Do you have any insights on what might be going wrong?

Answer №1

Connect to a string rather than the variable myname (which is located in mypage.ts)

<app-inputinline
            [name]="username"
            [fieldValue]="'myname'"
            [isRequired]="true"
            (updateValue)="saveField('username', $event)"></app-inputinline>

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

Issue: Unable to assign value to 'googleUri' property of null. Resolving with Interface for two-way binding?

Can anyone help me figure out why I keep getting a 'set property of null' error while attempting 2way binding in my interface? Whenever I submit the form and trigger the onSave function, I encounter the error "Cannot set property 'googleUri ...

Adjusting the size of the Knob in Ionic 5 upon pressing it

Is there a way to change the size of the knob in an "ion-range" element when it is pressed? I have checked the documentation, but could not find any information in the "ion-range" section. I would like to make this adjustment in SCSS: Normal Behavior Pre ...

Showing json information in input area using Angular 10

I'm facing an issue with editing a form after pulling data from an API. The values I retrieve are all null, leading to undefined errors. What could be the problem here? Here's what I've tried so far: async ngOnInit(): Promise<void> ...

Removing redundant names from an array using Typescript

My task involves retrieving a list of names from an API, but there are many duplicates that need to be filtered out. However, when I attempt to execute the removeDuplicateNames function, it simply returns an empty array. const axios = require('axios&a ...

Can anyone provide assistance on implementing multiple where conditions in a loop with Firebase and Angular?

I've been attempting to implement dynamic conditions on a firebase query, but I'm having issues getting it to work. I even tried using chatgpt, but that didn't provide me with the ideal solution either. Can someone please assist me in resolv ...

The offline functionality of the Angular Progressive Web App(PWA) is experiencing difficulties

As per the official guidelines, I attempted to create a PWA that functions in offline mode using pure PWA without angular-cli. However, despite following the official instructions, I was unable to make it work offline. The document in question can be foun ...

Issue with Adding Class to Angular2 Material Tooltips

Here is the code from my component.html file: <tr> <td> <span matTooltipClass="primary-tooltip" matTooltipPosition="above" matTooltipHideDelay="100000" matTooltip="{{cert.awsCertId}}"><p style="overflow:hidden;text-overflow: ellip ...

Can you explain the distinction between App: React.FunctionComponent and App = (): React.FunctionComponent()?

Currently exploring the depths of typescript. Can someone clarify the distinction between these two code snippets: const App: React.FunctionComponent<CustomProps> = (props: CustomProps) => { return <div>Hello World!</div>; }; and: ...

The call stack size has been exceeded in Next.js, resulting in a RangeError

Currently attempting to deploy my project on vercel.com but encountering an error specifically with 3 pages that have no internal errors. An error occurred while prerendering the page "/applications". For more information, visit: https://nextjs.org/docs/me ...

How can I make sure that the combobox in my Ionic app is aligned with the text fields in a row?

From the image provided, it's evident that my HTML code looks like this: <ion-row> <ion-col> <ion-item> <searchable-ion-select isModal="true" name="country" valueField="code" [(ngModel)]="country" title="Country" ...

Why does my ngFor consistently refresh while the array remains unchanged?

Issue at hand: Whenever I launch this component, the ngFor div continuously updates and causes my RAM to deplete. Typically, ngFor is triggered when the array is updated; however, in my case, the array (announcements) only updates once in the constructor. ...

Transferring an Image File from Angular 8 to a Spring Boot Application

Having trouble sending a file from my Angular 8 app to my Spring Boot server. I've tried using MultiPartFile and HttpServletRequest in Spring, among other methods, with no luck. I'm hoping someone can provide guidance on how to successfully retr ...

Encountering compilation errors with Angular project following installation of a package

I recently installed the LocalStorage Package and encountered the following message: npm notice created a lockfile as package-lock.json. You should commit this file. npm WARN @angular/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfem ...

Utilizing Angular 10 to Transform a JSON Data into a Custom String for HTML Rendering

I have received a JSON response from my backend built using Spring Boot. The "category" field in the response can either be 1 or 2, where 1 represents Notifications and 2 represents FAQs. { "pageNumber": 0, "size": 5, "totalPages&q ...

Encountered a style group error 'non-collision' while using Angular with HERE Maps JS API 3.1

Occasionally, I encounter an error when trying to load a HERE map with the satellite base layer: Tangram [error]: Error for style group 'non-collision' for tile 13/16/15542/12554/15 Cannot read property 'retain' of undefined: TypeE ...

Exploring the implementation of Observable within a Custom Validator in Angular

Currently, I am developing a custom validator to validate whether a username is already in use. Below is the definition of my Custom validator: import { AbstractControl } from '@angular/forms'; import { AccountApi } from '../../api/service ...

The process of running npx create-react-app with a specific name suddenly halts at a particular stage

Throughout my experience, I have never encountered this particular issue with the reliable old create-react-app However, on this occasion, I decided to use npx create-react-app to initiate a new react app. Below is a screenshot depicting the progress o ...

What are the best ways to troubleshoot my Angular 2 project?

I've been searching for my TypeScript files in the console, but they're not showing up. I've tried everything to debug my Angular 2 project, but no luck. I can't move forward without debugging, can anyone lend a hand? ...

Disabling the use of console.log() in a live environment

In an effort to disable console logs for production environments in my angular application, I implemented the code below. While it successfully suppresses logs in Chrome, IE 11 continues to display them. Here is the snippet from main.ts: if (environment. ...

Tips for implementing self-managed state in Vue.js data object

My approach in organizing my Vue application involves using classes to encapsulate data, manage their own state (edited, deleted, etc), and synchronize with the back-end system. However, this method seems to conflict with Vue in some respects. To illustra ...