Error when showing undefined variable


Shah

Error: _co.bellowContent is undefinedThere was an error displaying the data . You can quote my code below. There was an error Error: _co.bellowContent is undefineddisplaying the data . You can quote my code below.

app.component.html

<table class="table">
  <thead>
    <tr>
      <th scope="col">#</th>
      <th scope="col">First</th>
      <th scope="col">Last</th>
      <th scope="col">Title</th>
    </tr>
  </thead>
  <tbody>
    <tr *ngFor="let tableRow of table" (click)="open(tableRow)">
      <th scope="row">{{tableRow.id}}</th>
      <td>{{tableRow.first}}</td>
      <td>{{tableRow.last}}</td>
      <td>{{tableRow.title}}</td>
    </tr>
  </tbody>
</table>

<div>
<p>id: {{ bellowContent.id }}</p>
<p>first: {{ bellowContent.first }}</p>
<p>last: {{ bellowContent.last }}</p>
<p>title: {{ bellowContent.title }}</p>
</div>

and

app.component.ts

  bellowContent:undefined
  table = [
  {
    "id": 1,
    "first":"Robin",
    "last": "William",
    "title": "back end developer"
  },{
    "id": 2,
    "first":"Mark",
    "last": "Thornton",
    "title": "front end developer"
  },{
    "id": 3,
    "first":"Tary",
    "last": "Huction",
    "title": "front end developer"
  }
]


  open(tableRow) {
      this.bellowContent = tableRow
  }
}

Here is my code in stackBlitz

Sajeethharan

Since you defined it as undefined, first define it as undefined so that you can handle undefined errors. Use the "safe navigation" operator as follows,

<p>id: {{ bellowContent?.id }}</p>
<p>first: {{ bellowContent?.first }}</p>
<p>first: {{ bellowContent?.last }}</p>
<p>first: {{ bellowContent?.title }}</p>

Also the correct way to initialize bellowContent to an Empty object

 bellowContent = {};

STACKBLITZ DEMO

Related


Error when showing undefined variable

Shah Error: _co.bellowContent is undefinedThere was an error displaying the data . You can quote my code below. There was an error Error: _co.bellowContent is undefineddisplaying the data . You can quote my code below. app.component.html <table class="table">

Error when showing undefined variable

Shah Error: _co.bellowContent is undefinedThere was an error displaying the data . You can quote my code below. There was an error Error: _co.bellowContent is undefineddisplaying the data . You can quote my code below. app.component.html <table class="table">

Undefined variable not showing up as Java Eclipse error

New2Java2 Using Eclipse to enter and compile the following Java classes did not flag any errors in the code public class Test { public static void main(String args[]) { xCase = yCase + 100; } } The identifiers xCase and yCase are not defined c

Undefined variable not showing up as Java Eclipse error

New2Java2 Using Eclipse to enter and compile the following Java classes did not flag any errors in the code public class Test { public static void main(String args[]) { xCase = yCase + 100; } } The identifiers xCase and yCase are not defined c

Undefined variable error when defining variable

Julien Vincent When defining a variable, I get an "undefined variable" error. bellow is my code <?php $imagepath = $_SESSION['path']; require_once('class-db.php'); if ( !class_exists('INSERT') ) { class INSERT { public function post($postdata) {

Undefined variable error when defining variable

Julien Vincent When defining a variable, I get an "undefined variable" error. bellow is my code <?php $imagepath = $_SESSION['path']; require_once('class-db.php'); if ( !class_exists('INSERT') ) { class INSERT { public function post($postdata) {

PHP error showing undefined variable: file, unknown error

username PHP beginners Below is my code to retrieve file from folder but it shows me error Undefined variable: files Why am I getting this error. This is a photo gallery. Gallery folder doesn't have any images so far. <?php if($theRugz<>''){ /* s

PHP error showing undefined variable: file, unknown error

username PHP beginners Below is my code to retrieve file from folder but it shows me error Undefined variable: files Why am I getting this error. This is a photo gallery. Gallery folder doesn't have any images so far. <?php if($theRugz<>''){ /* s

PHP error showing undefined variable: file, unknown error

username PHP beginners Below is my code to retrieve file from folder but it shows me error Undefined variable: files Why am I getting this error. This is a photo gallery. The Gallery folder doesn't have any images so far. <?php if($theRugz<>''){

PHP error showing undefined variable: file, unknown error

username PHP beginners Below is my code to retrieve file from folder but it shows me error Undefined variable: files Why am I getting this error. This is a photo gallery. The Gallery folder doesn't have any images so far. <?php if($theRugz<>''){

extern undefined reference error when declaring variable

nepp95 I have 2 header files and 1 source file to work with. They are: Utility.h, Game.hand main.cpp. I have declared the external variable in . Utility.hand tried in main.cpp. This gave me an undefined reference error which I don't understand. I use the varia

"Undefined variable" error when running tcsh script

Senna I'm trying to execute every script that has "~SAC" at the end of the filename. For this, I wrote tc shell script using "foreach" like the code below. However, when I execute it by typing ./run.tcsh, it just shows "tmpdir: Undefined variable". ("tmpdir" i

variable declared but still showing undefined

Takasato I have a select list and when changing it I need to set a variable to true. I have written the code as shown below. $(document).ready(function () { var value = false; console.log(value) //Get value = false $("#select").on('change', function(){ val

variable declared but still showing undefined

Takasato I have a select list and when changing it I need to set a variable to true. I have written the code as shown below. $(document).ready(function () { var value = false; console.log(value) //Get value = false $("#select").on('change', function(){ val

variable not updating in vue js, showing variable undefined

Sangram Badi I am trying to bind the updated value of a variable in totalQuestionshtml . But it shows the following error. Can anyone tell me what I am doing wrong. HTML <label><span class="red-text">Question No: </span><span>1 out of {{totalQuestions}}</span>

variable not updating in vue js, showing variable undefined

Sangram Badi I am trying to bind the updated value of a variable in totalQuestionshtml . But it shows the following error. Can anyone tell me what I am doing wrong. HTML <label><span class="red-text">Question No: </span><span>1 out of {{totalQuestions}}</span>

showing error undefined index: password

Rafik Malek my session controller i coded for validation email, login and changepassword but getting error ErrorException in EloquentUserProvider.php line 116: Undefined index: password. and get the error from the line of code if (!Auth::attempt($credentials_v

showing error undefined index: password

Rafik Malek my session controller i coded for validation email, login and changepassword but getting error ErrorException in EloquentUserProvider.php line 116: Undefined index: password. and get the error from the line of code if (!Auth::attempt($credentials_v

showing error undefined index: password

Rafik Malek my session controller i coded for validation email, login and changepassword but getting error ErrorException in EloquentUserProvider.php line 116: Undefined index: password. and get the error from the line of code if (!Auth::attempt($credentials_v

showing error undefined index: password

Rafik Malek my session controller i coded for validation email, login and changepassword but getting error ErrorException in EloquentUserProvider.php line 116: Undefined index: password. and get the error from the line of code if (!Auth::attempt($credentials_v

Error in jQuery showing ID is undefined

sasswater I have a jQuery script that creates a div this way function dump_template(src,close_div) { var item_template = $('<img/>', {'id':'target','src':src}); var first_text = $('<div/>', {'id':'first_text','class':'edit_text'}); $(first_text).cs