Skip to content

Instantly share code, notes, and snippets.

View tkssharma's full-sized avatar
🎯
only JS

codewithtkssharma tkssharma

🎯
only JS
View GitHub Profile
@Component({
selector: 'video-list',
templateUrl: 'video-list.html'
})
class VideoList implements OnInit {
@Input() Videos:video[] ;
@Output() clickParentChange = new EventEmitter();
ngOnInit(){
request(url: string | Request, options?: RequestOptionsArgs): Observable<Response>;
/**
* Performs a request with `get` http method.
*/
get(url: string, options?: RequestOptionsArgs): Observable<Response>;
/**
* Performs a request with `post` http method.
*/
post(url: string, body: any, options?: RequestOptionsArgs): Observable<Response>;
/**
@Injectable()
export class CommentService {
// Resolve HTTP using the constructor
constructor (private http: Http) {}
// private instance variable to hold base url
private commentsUrl = 'http://localhost:3000/api/comments';
}
getComments() : Observable<Comment[]> {
// ...using get request
return this.http.get(this.commentsUrl)
// Add a new comment
addComment (body: Object): Observable<Comment[]> {
let bodyString = JSON.stringify(body); // Stringify payload
let headers = new Headers({ 'Content-Type': 'application/json' }); // ... Set content type to JSON
let options = new RequestOptions({ headers: headers }); // Create a request option
return this.http.post(this.commentsUrl, body, options) // ...using post request
.map((res:Response) => res.json()) // ...and calling .json() on the response to return data
.catch((error:any) => Observable.throw(error.json().error || 'Server error')); //...errors if any
}
import {Injectable} from '@angular/core';
import {Http, Headers, Response, Request, BaseRequestOptions, RequestMethod, ResponseContentType} from '@angular/http';
import {Observable} from 'rxjs/Rx';
@Injectable()
export class HttpClient {
constructor(private http: Http) {}
post(url: string, body: any = {}) {
return this.request(url, RequestMethod.Post, body);
}
@Injectable()
export class cartService {
constructor(private httpclient : HttpClient) {}
private cartSubject = new Subject<CartState>();
Products : product[]= [];
CartState = this.cartSubject.asObservable();
addProduct(_product:any) {
console.log('in service');
this.Products.push(_product)
this.cartSubject.next(<CartState>{loaded: true, products: this.Products});
export default class shoppingCartItem {
@Input()product : product;
constructor(private _cartService : cartService) {}
AddProduct(_product : product) {
_product.added = true;
this
._cartService
.addProduct(_product);
}
RemoveProduct(_product : product) {
export default class shoppingList {
loaded : boolean = true
products : product[];
private subscription : Subscription;
constructor(private _cartService : cartService) {}
ngOnInit() {
// this.loaderService.show();
this.subscription = this._cartService.CartState
.subscribe((state : CartState) => {
this.products = state.products;
var quizQuestions = [
{
question: "What franchise would you rather play a game from?",
answerindex : 1,
answers: [
{
type: "IBM",
content: "Halo",
answer : false
},
class App extends Component {
constructor(props) {
super(props);
this.state = {
counter: 0,
questionId: 1,
question: '',
answerOptions: [],