Skip to content

Instantly share code, notes, and snippets.

@PradeepLoganathan
Last active March 13, 2018 06:02
Show Gist options
  • Save PradeepLoganathan/169d637d2cae8f1da6fc1231e02da648 to your computer and use it in GitHub Desktop.
Save PradeepLoganathan/169d637d2cae8f1da6fc1231e02da648 to your computer and use it in GitHub Desktop.
A component which uses the subscription service
import { Observable } from "rxjs/Observable";
import { Subscription } from "rxjs/Subscription";
import { IProduct } from "../../models/subscription.Models/Products/Core/IProduct";
import { ProductService } from "../../core/services/ProductService/product.service";
@Component({
selector: "app-product-manager",
templateUrl: "./productmanager.component.html",
styleUrls: ["./productmanager.component.css"]
})
export class ProductsManagerComponent
implements OnInit, OnDestroy {
productObservable: Subscription;
constructor(
private fb: FormBuilder,
private productService: ProductService
) {
}
ngOnInit() {
this.createProductDetailsForm();
}
ngOnDestroy(): void {
if (this.productObservable) this.productObservable.unsubscribe();
}
getProductToDisplay(productID:number){
this.productObservable = this.productService
.getProduct(productID)
.subscribe(
data:IProduct => {
console.log(`Data in product get is ${data}`);
this.onGetComplete(data);
},
(error: any) => console.log(`error occured -- ${error}`)
);
}
onGetComplete(product:IProduct){
//display the product details
//Maybe bind to form variables
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment