Angular 4 throwing an error: Attempting to access the 'value' property of an undefined object leads to a TypeError

Encountering an error in Angular 4 (Angular-CLI) that reads:

TypeError: Cannot read property 'value' of undefined
. I am transitioning from Angular 1 to Angular 4 and would appreciate any help. Thank you in advance.

Below is my code snippet:

app.component.html

<!-- using semantic-ui --> 
<form class="ui large form segment">
  <h3 class="ui header">Add a link</h3>
  <!-- added the title -->

  <div class="field">
    <label for="title">Title:</label>
    <input name="title" #newtitle>
  </div>
  <!-- added the link -->
  <div class="field">
    <label for="link">Link:</label>
    <input name="link" #newLink>
  </div>
  <!--added the button -->

  <button (click)="addArticle(newTitle, newLink)" class="ui positive right floated button">
    Submit Link
  </button>

</form>

app.component.ts

import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})

export class AppComponent {

  addArticle(title: HTMLInputElement, link: HTMLInputElement):
    boolean {
    console.log(`Adding article title: ${title.value} 
    and link: ${link.value}`);
    return false;
  }
}

Answer №1

The reference variable casing does not match the parameter passed. Adjust

<input name="title" #newtitle>
to
<input name="title" #newTitle>
because you are using addArticle with newTitle with a capital T.

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

manipulating elements of an array within a .map method

i am stuck with a json exporting database. it generates json data in the following format. {"Drinks":[ { "name":"name", "discription":"discription", "image":"image", "ingredients&qu ...

Using the Primefaces ajax feature to pass a parameter to JavaScript for callback execution

Struggling with sending a Primefaces bean property to JavaScript directly in order to open a new page and write the content of the bean property into it. The version of Primefaces being used is 4.0. A command button that is being utilized looks like this ...

Modifying the *ngIf structural directive to display the content of the panel that is clicked, while hiding the content of all other

One of my recent projects involved creating a reusable panel component with unique bodies for each instance. Here is the code for my customizable panel: <div class="panel panel-default" (click)="openPanelBody($index)"> <div class="panel-headi ...

Can you explain the concept of asynchronous in the context of Ajax?

Can you explain the concept of Asynchronous in Ajax? Additionally, how does Ajax determine when to retrieve data without constantly polling the server? ...

What is the procedure for matching paths containing /lang using the express middleware?

I need to target paths that contain /lang? in the URL, but I am unsure how to specifically target paths that begin with /lang? I have two routes: app.get('/lang?..... app.get('/bottle/lang?....... I want to target these routes using app.use(&a ...

CDK deployment of lambda functions does not currently support the importing of Typescript modules

I’m currently using CDK to develop my serverless application in AWS. However, I encountered an issue where the lambda function fails to import TypeScript modules as JavaScript modules post TS file compilation. As a result, I am encountering a “Module ...

Importing cookies directly into server actions in Next JS 13 is not possible for me

Currently, I am tackling a project using Next JS 13 and came across an issue pertaining to server actions. While server actions can be directly applied on form or button components, my personal preference is to define server components in separate files an ...

Angular 7 Populate model array with Subscribe

I am currently working with Angular 7 and I need to populate my array model with the data returned from a subscription. Here is what I have so far: rsvp: RSVP[]; constructor(private rsvpService: EventoRsvpService) { } ngOnInit() { this.rsvpS ...

The Ajax query returned a successful response, yet it unexpectedly triggered an error

Currently, I am delving into the realm of mongodb. I have integrated Express, Body-Parser, and Mongoose into my project, and I'm retrieving data from an online mongodb database hosted on mlab. Everything seems to be functioning smoothly as I've t ...

Can JSPDF Autotable support line breaks with unique styles for each line?

Is it possible to create rows in jspdf autotable with two sets of information on separate lines in each cell? Currently, I am using the "\n" operator to display the information on different lines within the same cell. However, I'm looking for a ...

Spring's $.getJSON failing to trigger callback functions

After conducting extensive research, I have come across many similar issues but nothing that has provided a solution to my problem. I am facing an issue where my getJSON call is successfully calling my Spring controller and receiving JSON data in response ...

Exploring the functionality of dimensions in d3 parcoords

I am diving into the world of d3 and experimenting with Behold, a simplistic example directly from the website. <script src="http://d3js.org/d3.v3.min.js"></script> <script src="d3.parcoords.js"></script> <link rel="stylesheet" ...

JQuery table sorter is unable to effectively sort tables with date range strings

I am facing an issue with sorting a column in my table that contains text with varying dates. The text format is as follows: Requested Statement 7/1/2014 - 9/16/2014 When using tablesorter, the sorting does not work properly for this column. You can see ...

Troubleshooting: When attempting to integrate a Flask Backend with a NextJS frontend, encountering issues with files not being received properly

I have developed a Flask Backend with the purpose of accepting and processing files. Recently, I created a Next.js frontend where users can upload files. Strangely enough, when I followed the same steps as in my Flask project using a template HTML file, it ...

What is preventing you from utilizing JavaScript or jQuery to showcase a dropdown menu?

As a JavaScript novice, I find myself wondering about the following issue. I've seen it pop up numerous times on Stack Overflow. Can JS be leveraged to unveil an HTML select element and display its list of options? How can you instruct an HTML SELECT ...

Exploring trees with jQuery: A guide to traversal techniques

<ul id="org" style="display:none"> <li id="visited"><a href="#" class="ui-link">ROOT</a> <ul id="main_child_ul" class="children"> <li><a href="#">Acura</a> & ...

Refresh the page twice using ajax/jQuery and setTimeout function

When it comes to Ajax, Java script or CSS, I must confess that I struggle a bit. So please bear with me as I ask for some assistance. I am currently working on a CMS wrapped in Jquery mobile and unable to use meta refresh methods. How can I adjust the code ...

One of three hidden divs suddenly appears on the screen when a button is clicked, standing out from the rest

Currently, I have 3 divs set up: var t1 = document.getElementById("tafel1"); var t2 = document.getElementById("tafel2"); var t3 = document.getElementById("tafel3"); function tafel1() { if (t1.style.display === "none") { ...

"Implementing a Node.js/Express backend paired with an Angular front-end within a unified Azure web application

Currently, I have set up a Node/Express configuration for my development environment that provides JSON data through the endpoint localhost:3000/data. In addition to this, there is an Angular 8 application within the same node directory for the frontend. ...

What could be causing my webpage to automatically refresh following a POST request in NodeJS?

Utilizing the express framework alongside NodeJS, I have encountered an issue where my client webpage refreshes after making a POST request that triggers a python script and returns a JSON object to the client. My dilemma lies in preventing this automatic ...