Uploading information from ngModel to Firebase

I am currently facing an issue while trying to store user input data into Firebase. Below is the code snippet for my input field:

<div class="bed-price cc">
                <label for="name" class="subtitle-secondary">Name</label>
                <input *ngIf="pePropertyStep" type="text" name="name" class="minimal_input shadow_xlight"
                       [(ngModel)]="pePropertyStep.mid_tenants.mid_tenant_name"  #name="ngModel" placeholder="Name">
              </div>

This is the model structure I am using:

export interface PropertyPropertyModel {
  description: string;
  lease_type: string;
  is_mid_tenancy: boolean;
  mid_tenants: Array<{ mid_tenant_name: string, mid_tenant_email: string, mid_tenant_rent_price: number, status: string}>;
}

This is how I initialize it:

initPropertyProperty = (): PropertyPropertyModel => {
    return {
      description: '',
      is_mid_tenancy: false,
      mid_tenants: [
        { mid_tenant_name: '', mid_tenant_email: '', mid_tenant_rent_price: 0, status: 'pending'}
      ],
}

And here's how I populate it:

populatePropertyProperty = (property: PropertyModel): PropertyPropertyModel => {
    return {
      description: property.description,
      is_mid_tenancy: property.is_mid_tenancy,
      mid_tenants: property.mid_tenants,
}

Despite having successfully used similar methods to upload data to Firebase before, this time I encounter an error in console even before attempting to push data. The specific error message reads:

ERROR TypeError: Cannot read property 'mid_tenant_name' of undefined
    at Object.eval [as updateDirectives] (PeInfoPropertyComponent.html:19)

This error seems to be originating from the HTML section mentioned above. Could it possibly be related to the utilization of an array of objects in this scenario?

Answer №1

The reason is that the property mid_tenants has been declared as an array in your model, but you are not accessing it correctly. You need to specify the position of the array in order to access the object. Here's an example:

 [(ngModel)]="pePropertyStep.mid_tenants[0].mid_tenant_name" 

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

Maximizing Efficiency of Vendor Bundle in Angular 2 with Webpack

My MEAN application's client side is built in Angular2 with Webpack, but I'm facing slow loading times due to a large vendor modules JS file. Is there a way to optimize this situation? I want to separate the vendor's JS file. Below is my we ...

Implementing ValidateAntiForgeryToken with Angular 7 and ASP.NET Web API: Step-by-Step Guide

Currently, my application's server side is constructed using Asp.Net web api while the client side uses Angular 7. I have come across numerous examples demonstrating how to incorporate ValidateAntiForgeryToken in various scenarios such as web forms, ...

Transform the JSON object into a different JSON format

I am in the process of restructuring the JSON data which is currently organized by categories, with each category containing multiple locations. Each location consists of latitude/longitude coordinates and an area code: { "cat1":[ {"location":{ ...

Struggling to retrieve dataset from Bootstrap 5 form while using Angular

With the combination of Angular and Bootstrap 5, I have crafted this unique HTML form: <div class="mb-3"> <label for="genreName"> Type name</label> <div *ngIf="!enterTheGenre" class="form-group&qu ...

Activate jQuery after a vanilla JavaScript function has been executed

I have created a jQuery function that captures any changes made to an input field and stores them in a variable. The input field is connected to a vanilla JavaScript based API library, which I am unable to convert to jQuery. This library is for an address ...

Animating back with a jQuery if statement

Is there a way to implement an if statement that triggers an animation when the right image reaches +400px, and then animates back to -400px upon hovering over the image? $('#left img').mouseenter(function() { $('#right img').animate ...

I am attempting to achieve a smooth transition effect by fading in and out the CSS background color using JQuery and AJAX

Can anyone help me with my issue related to using Ajax to fadeIn a background color in beforeSend and fadeOut in success? I seem to have made some mistakes but can't figure out what went wrong. var data={ ...

I'm curious about the distinction between React's one-way data binding and Angular's two-way data binding. Can someone please clarify the key differences

My understanding of these concepts is a bit hazy. If I were to develop the same ToDo application using AngularJS and ReactJS, what exactly distinguishes React ToDo's use of one-way data binding from AngularJS's two-way data binding? From what I ...

Can the Date class be expanded by overloading the constructor method?

In my dataset, there are dates in different formats that Typescript doesn't recognize. To address this issue, I developed a "safeDateParse" function to handle extended conversions and modified the Date.parse() method accordingly. /** Custom overload ...

JavaScript transform numbers into array of buffers with a length of 4

I'm looking for a way to insert a numerical value into an array of 4 values [uint32_t] For example 255 should look like [0x00, 0x00, 0x00, 0xFF] I need to transmit this value from a Node.js server to an Arduino board Is there a built-in solution or ...

Http provider not found in Angular 4 when using Rails 5 API

I recently completed a tutorial on Angular and Rails which I found here, but I am encountering difficulties in implementing it successfully. Currently, I am working with Angular version 4.2.4. [Error] ERROR Error: No provider for Http! injectionError — ...

Exploring Nested JSON Iteration in Angular4

I am struggling to iterate through a nested JSON and extract the desired output. Can someone assist me in retrieving the bpmn:startEvent id value from the JSON provided below? { "bpmn:definitions":{ "@attributes":{ "xmlns:xsi":"h ...

Dynamic jquery multiple select menu not refreshing properly

Welcome to the new year! I am currently working on creating a multiple select list with the attribute (data-native-menu="false"). The and elements are dynamically generated through a websql query. However, when I execute the code, none of the options are ...

The function 'compilation.emitAsset' is not recognized by the sitemap-webpack-plugin

I'm currently working on setting up a sitemap for my live environment and I've encountered an issue while trying to utilize the sitemap-webpack-plugin. The error message I received is as follows: ERROR in TypeError: compilation.emitAsset is not a ...

What is the method for initializing fancybox with the precise image index?

My current usage of fancybox involves the following code snippet: $("a[rel=Fancy" + UserId + "].Items").fancybox({ 'autoscale': 'false', 'cyclic': true, 'transitionIn': 'elastic', & ...

Why does the JavaScript code work perfectly in Mozilla, but show an unknown runtime error in IE6?

When building my page, I implemented a simple blow up trick. Initially, the div is set as hidden, and when the image is clicked, a blow up effect occurs with an overlay image in the background. The JavaScript function updates the innerHTML. While this work ...

The <form> element is giving me headaches in my JavaScript code

Trying to troubleshoot why my HTML pages render twice when I add a form with JavaScript. It seems like the page displays once with the script and again without it. Below is the basic HTML code: <form action="test.php" method="post"> <div class=" ...

Access a three.js scene from a canvas element within the local environment to make alterations

Is it necessary to keep Three.js variables (scene, camera, renderer etc.) globally? I have devised a function that initializes canvas elements by taking a DOM position and other information to build the scene. This function is then passed to a render func ...

Creating Docker images in a lerna monorepo without the need for publishing

In the context of Lerna monorepos, the primary goal is to facilitate branch building and deployments. The challenge arises from the fact that Lerna monorepos either consolidate dependencies in NPM or utilize yarn workspaces to achieve the same outcome, re ...

Retrieve the output of a Node.js function

I have a function that extracts data from a website and displays it in the console. However, I now want to return this data so I can perform additional actions with it. Instead of using console.log(temperature), I would like to retrieve the temperature v ...