Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. --- Store component ---
  2. export class StoreComponent implements OnInit {
  3.  
  4. private items: ItemComponent[] = ItemService.get_items();
  5. constructor(itemService: ItemService) {}
  6. }
  7.  
  8. --- Item component ---
  9. export class ItemComponent implements OnInit {
  10.  
  11. constructor(private _name: string, private _unitPrice: number, private
  12. _description?:string, private _image?:string) { }
  13.  
  14. ngOnInit() {
  15. }
  16.  
  17.  
  18. get name(){return this._name;}
  19. get unitPrice(){return this._unitPrice}
  20. get description(){return this._description;}
  21. get image(){return this._image;}
  22.  
  23. }
  24.  
  25. --- store component html (worked) ---
  26. <div id="items">
  27. <th>Name</th>
  28. <th>unitPrice</th>
  29. <th>description</th>
  30. <tr *ngFor='let item of items'>
  31. <td>{{item.name}}</td>
  32. <td>{{item.unitPrice}}</td>
  33. <td>{{item.description}}</td>
  34. </tr>
  35. </div>
  36.  
  37. --- New Store component html (doesn't work) ---
  38. <div id="items">
  39. <th>Name</th>
  40. <th>unitPrice</th>
  41. <th>description</th>
  42. <app-item *ngFor='let item of items'></app-item>
  43. </tr>
  44. </div>
  45.  
  46. --- New Item component html (doesn't show) ---
  47. <tr>
  48. <td>{{name}}</td>
  49. <td>{{unitPrice}}</td>
  50. <td>{{description}}</td>
  51. </tr>
  52.  
  53.  
  54. --- After I edited the html code, I get following error: ---
  55.  
  56. ERROR NullInjectorError: StaticInjectorError(AppModule)[ItemComponent ->
  57. String]:
  58. StaticInjectorError(Platform: core)[ItemComponent -> String]:
  59. NullInjectorError: No provider for String!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement