Created
December 6, 2017 03:12
-
-
Save thefln/54b1786b1a56c187b1bc7379344efaf0 to your computer and use it in GitHub Desktop.
product-details-component.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Component } from '@angular/core'; | |
| import { OnInit } from '@angular/core'; | |
| import { HttpClient } from '@angular/common/http'; | |
| import { ActivatedRoute } from '@angular/router'; | |
| @Component({ | |
| selector: 'app-root', | |
| templateUrl: './product.component.html', | |
| styleUrls: ['./../../app.component.css'], | |
| }) | |
| export class ProductComponent implements OnInit { | |
| constructor( | |
| private http: HttpClient, | |
| private route: ActivatedRoute) {} | |
| product: object; | |
| setProduct(id): void { | |
| var query = `*[_id == '${id}']{ name, _id, description, price, 'imageUrl': image.asset->url }`; | |
| this.http | |
| .get(`https://7abtqvex.apicdn.sanity.io/v1/data/query/products?query=${query}`) | |
| .subscribe(data => { | |
| this.product = data["result"][0]; | |
| }); | |
| } | |
| ngOnInit(): void { | |
| this.route.url | |
| .subscribe(curr => { | |
| this.setProduct(curr[1].path); | |
| }) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment