Guest User

Untitled

a guest
Feb 17th, 2018
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.07 KB | None | 0 0
  1. ERROR in srcappadminproduct-formproduct-form.component.html(10,11): : Property 'title' does not exist on type '{}'.
  2. srcappadminproduct-formproduct-form.component.html(27,13): : Property 'price' does not exist on type '{}'.
  3. srcappadminproduct-formproduct-form.component.html(48,11): : Property 'category' does not exist on type '{}'.
  4. srcappadminproduct-formproduct-form.component.html(66,11): : Property 'imageUrl' does not exist on type '{}'.
  5. srcappadminproduct-formproduct-form.component.html(10,11): : Property 'title' does not exist on type '{}'.
  6. srcappadminproduct-formproduct-form.component.html(27,13): : Property 'price' does not exist on type '{}'.
  7. srcappadminproduct-formproduct-form.component.html(48,11): : Property 'category' does not exist on type '{}'.
  8. srcappadminproduct-formproduct-form.component.html(66,11): : Property 'imageUrl' does not exist on type '{}'.
  9.  
  10. product = {};
  11.  
  12. product: Product;
  13.  
  14. Error: Cannot read property 'title' of undefined
  15.  
  16. product: Product = {};
  17.  
  18. ERROR in src/app/admin/product-form/product-form.component.ts(15,5): error TS2322: Type '{}' is not assignable to type 'Product'.
  19. Property '$key' is missing in type '{}'.
  20.  
  21. import { Component, OnInit } from '@angular/core';
  22. import { CategoryService } from '../../category.service';
  23. import { ProductService } from '../../product.service';
  24. import { Router, ActivatedRoute } from '@angular/router';
  25. import 'rxjs/add/operator/take';
  26.  
  27. @Component({
  28. selector: 'app-product-form',
  29. templateUrl: './product-form.component.html',
  30. styleUrls: ['./product-form.component.css']
  31. })
  32. export class ProductFormComponent implements OnInit {
  33. categories$;
  34. product = {};
  35. id;
  36.  
  37. constructor(
  38. private router: Router,
  39. private route: ActivatedRoute,
  40. private categoryService: CategoryService,
  41. private productService: ProductService
  42. ) {
  43. this.categories$ = categoryService.getAll();
  44.  
  45. this.id = this.route.snapshot.paramMap.get('id');
  46. if (this.id) {
  47. this.productService
  48. .get(this.id)
  49. .take(1)
  50. .subscribe(p => (this.product = p));
  51. }
  52. }
  53.  
  54. save(product) {
  55. if (this.id) {
  56. this.productService.update(this.id, product);
  57. } else {
  58. this.productService.create(product);
  59. }
  60. this.router.navigate(['/admin/products']);
  61. }
  62.  
  63. delete() {
  64. if (!confirm('Are you sure you want to delete?')) {
  65. return;
  66. }
  67. this.productService.delete(this.id);
  68. this.router.navigate(['/admin/products']);
  69. }
  70.  
  71. ngOnInit() {}
  72. }
  73.  
  74. <div class="row">
  75. <div class="col-md-6">
  76.  
  77. <form #f="ngForm"
  78. (ngSubmit)="save(f.value)">
  79.  
  80. <div class="form-group">
  81. <label for="title">Title</label>
  82. <input #title="ngModel"
  83. [(ngModel)]="product.title"
  84. name="title"
  85. tobject
  86. ;product
  87. 'ype="text"
  88. id="title"
  89. class="form-control"
  90. required>
  91. <div class="alert alert-danger"
  92. *ngIf="title.touched && title.invalid">Title is required.</div>
  93. </div>
  94.  
  95. <div class="form-group">
  96. <label for="price">Price</label>
  97. <div class="input-group">
  98. <div class="input-group-addon">
  99. <span class="input-group-text">$</span>
  100. </div>
  101. <input #price="ngModel"
  102. [(ngModel)]="product.price"
  103. name="price"
  104. type="number"
  105. class="form-control"
  106. aria-label="Amount (to the nearest dollar)"
  107. required
  108. [min]="0">
  109. <div class="input-group-append">
  110. <span class="input-group-text">.00</span>
  111. </div>
  112. </div>
  113. <div class="alert alert-danger"
  114. *ngIf="price.touched && price.invalid">
  115. <div *ngIf="price.errors.required">Price is required.</div>
  116. <div *ngIf="price.errors.min">Price must be equal to or greater than zero.</div>
  117. </div>
  118. </div>
  119.  
  120. <div class="form-group">
  121. <label for="category">Category</label>
  122. <select #category="ngModel"
  123. [(ngModel)]="product.category"
  124. name="category"
  125. id="category"
  126. class="form-control"
  127. required>
  128. <option value=""></option>
  129. <option *ngFor="let c of categories$ | async"
  130. [value]="c.$key">
  131. {{ c.name }}
  132. </option>
  133. </select>
  134. <div class="alert alert-danger"
  135. *ngIf="category.touched && category.invalid">Category is required.</div>
  136. </div>
  137.  
  138. <div class="form-group">
  139. <label for="imageUrl">Image URL</label>
  140. <input #imageUrl="ngModel"
  141. [(ngModel)]="product.imageUrl"
  142. name="imageUrl"
  143. type="text"
  144. id="imageUrl"
  145. class="form-control"
  146. required
  147. url>
  148. <div class="alert alert-danger"
  149. *ngIf="imageUrl.touched && imageUrl.invalid">
  150. <div *ngIf="imageUrl.errors.required">Image URL is required.</div>
  151. <div *ngIf="imageUrl.errors.url">Image URL must be formatted correctly.</div>
  152. </div>
  153. </div>
  154. <button class="btn btn-primary">Save</button>
  155. <button type="button"
  156. class="btn btn-danger"
  157. (click)="delete()">Delete</button>
  158. </form>
  159. </div>
  160.  
  161. <div class="col-md-6">
  162. <product-card [product]="product"
  163. [show-actions]="false"></product-card>
  164. </div>
  165. </div>
  166.  
  167. export interface Product {
  168. $key: string;
  169. title: string;
  170. price: number;
  171. category: string;
  172. imageUrl: string;
  173. }
Add Comment
Please, Sign In to add comment