Guest User

Untitled

a guest
May 14th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 KB | None | 0 0
  1. ERROR TypeError: Cannot read property 'id' of undefined
  2. at Object.eval [as updateRenderer] (PlantDetailComponent.html:11)
  3. at Object.debugUpdateRenderer [as updateRenderer] (core.js:14735)
  4. at checkAndUpdateView (core.js:13849)
  5. at callViewAction (core.js:14195)
  6. at execComponentViewsAction (core.js:14127)
  7. at checkAndUpdateView (core.js:13850)
  8. at callViewAction (core.js:14195)
  9. at execEmbeddedViewsAction (core.js:14153)
  10. at checkAndUpdateView (core.js:13845)
  11. at callViewAction (core.js:14195)
  12.  
  13. ERROR CONTEXT DebugContext_ {view: {…}, nodeIndex: 0, nodeDef: {…}, elDef: {…}, elView: {…}}
  14.  
  15. import { Injectable } from '@angular/core';
  16. import { HttpClient, HttpHeaders } from '@angular/common/http';
  17. import { Observable } from 'rxjs/Observable';
  18. import { catchError, map, tap } from 'rxjs/operators';
  19. import { of } from 'rxjs/observable/of';
  20. import { Plant } from './plant';
  21.  
  22. @Injectable()
  23. export class PlantService {
  24. private plantsUrl = 'api/plants';
  25.  
  26. constructor(private http: HttpClient) { }
  27.  
  28. getPlants(): Observable<Plant[]> {
  29. return this.http.get<Plant[]>(this.plantsUrl)
  30. .pipe(
  31. catchError(this.handleError('getPlants', []))
  32. );
  33. }
  34.  
  35. getPlant(id: number): Observable<Plant> {
  36. const url = `${this.plantsUrl}/${id}`;
  37. return this.http.get<Plant>(url).pipe(
  38. catchError(this.handleError<Plant>(`getPlant id=${id}`))
  39. );
  40. }
  41.  
  42. private handleError<T>(operation = 'operation', result?: T) {
  43. return (error: any): Observable<T> => {
  44. console.error(error);
  45. return of(result as T);
  46. };
  47. }
  48. }
  49.  
  50. import { Component, OnInit, Input } from '@angular/core';
  51. import { ActivatedRoute } from '@angular/router';
  52. import { Location } from '@angular/common';
  53.  
  54. import { Plant } from '../plant';
  55. import { PlantService } from '../plant.service';
  56.  
  57. @Component({
  58. selector: 'app-plant-detail',
  59. templateUrl: './plant-detail.component.html',
  60. styleUrls: ['./plant-detail.component.css']
  61. })
  62. export class PlantDetailComponent implements OnInit {
  63. plant: Plant;
  64.  
  65. constructor(private route: ActivatedRoute,
  66. private plantService: PlantService,
  67. private location: Location
  68. ) {}
  69.  
  70. ngOnInit(): void {
  71. this.getPlant();
  72.  
  73. }
  74.  
  75. getPlant(): void {
  76. const id = +this.route.snapshot.paramMap.get('id');
  77. this.plantService.getPlant(id)
  78. .subscribe(plant => this.plant = plant);
  79. }
  80.  
  81. goBack(): void {
  82. this.location.back();
  83. }
  84.  
  85. }
  86.  
  87. var express = require("express");
  88. var mysql = require('mysql');
  89. var connection = mysql.createConnection({
  90. host: 'localhost',
  91. user: 'root',
  92. password: 'root',
  93. database: 'plant_care',
  94. });
  95. var app = express();
  96.  
  97. app.get("/api/plants", function(req, res) {
  98. connection.query('SELECT * FROM plant', function(err, rows, fields) {
  99. if (!err)
  100. res.send(rows);
  101. else
  102. console.log('Error while performing Query.');
  103. });
  104. });
  105.  
  106. app.get("/api/plants/:id", function(req, res) {
  107. const requestedID = req.params.id;
  108. connection.query('SELECT * FROM plant WHERE ID = ' + requestedID, function(err, rows, fields) {
  109. if (!err)
  110. res.send(rows);
  111. else
  112. console.log('Error while performing Query.');
  113. });
  114. });
  115.  
  116. app.listen(3000, function() {
  117. console.log("Running...");
  118. });
  119.  
  120. app.get("/api/plants/:id", function(req, res) {
  121. const requestedID = req.params.id;
  122. connection.query('SELECT * FROM plant WHERE ID = ' + requestedID, function(err, rows, fields) {
  123. if (!err)
  124. res.send(rows[0]);
  125. else
  126. console.log('Error while performing Query:n' + err);
  127. });
  128. });
Add Comment
Please, Sign In to add comment