Skip to content

Instantly share code, notes, and snippets.

@galek
Created June 15, 2019 12:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save galek/dbdf988dfd1c55a63ad613b720973a5b to your computer and use it in GitHub Desktop.
Save galek/dbdf988dfd1c55a63ad613b720973a5b to your computer and use it in GitHub Desktop.
Category
/**
* Login page logic
* last edit 27.04.19 20:31
* Author: NickGalko nikolay.galko@gmail.com
*
* Changes:
* 1) Fix for logic, show error messeage received from server
*/
import { Component } from '@angular/core';
import { NavController, Platform, NavParams } from 'ionic-angular';
import { API } from '../../code/apiprovider';
import { FormBuilder } from "@angular/forms";
import { GlobalUserInfo } from '../../code/globaluserinfo';
import { SettingsContainer } from '../../code/settings';
import { PagesHelper } from '../../code/pagesHelper';
@Component({
selector: 'page-category-module',
templateUrl: 'Category.html'
})
export class CategoryPage {
loading: boolean = true;
products: any;
subCategories: any;
heading_title: string = "";
slides: any = [];
constructor(public formBuilder: FormBuilder,
public navCtrl: NavController,
public navParams: NavParams,
public api: API,
public user: GlobalUserInfo,
public settings: SettingsContainer,
public pl: Platform) {
this.slides.push("test");
this.slides.push("test");
this.slides.push("test");
this.slides.push("test");
this.slides.push("test");
this.slides.push("test");
this.slides.push("test");
this.slides.push("test");
this.slides.push("test");
this.slides.push("test");
this.slides.push("test");
this.slides.push("test");
this.slides.push("test");
this.slides.push("test");
this.slides.push("test");
this.slides.push("test");
}
private _getDataFromServer(_id: string) {
this.loading = true;
if (!this.api) {
console.error("Not exist api");
return;
}
this.api.getItem("product/category&path=" + _id).subscribe(
value => {
this.products = value.products;
this.subCategories = value.categories;
this.heading_title = value.heading_title;
this.loading = false;
},
error => {
console.error(error);
this.loading = false;
});
// this.api.getItem("product/category&path=" + _id).toPromise().then(value => {
// this.products = value.products;
// this.subCategories = value.categories;
// this.heading_title = value.heading_title;
// this.loading = false;
// }).catch(error => {
// console.error(error);
// this.loading = false;
// });
}
// ionViewDidLoad() {
ngOnInit() {
console.error("6");
var id = this.navParams.get('id');
if (id == undefined) {
console.error("Invalid product id");
return;
}
this._getDataFromServer(id);
}
getProduct(product_id: number) {
PagesHelper.goToProductPage(this.navCtrl, false, { id: product_id });
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment