UNPKG

@calf/angular

Version:

Angular module of Calf framework.

68 lines (67 loc) 2.11 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; // Classes import { Subscriber } from "../classes/subscriber.class"; /** * Angular detail page */ export class DetailPage { /** * Constructor * @param service */ constructor(service) { this.service = service; /** * Subscriber */ this.subscriber = new Subscriber(); /** * Object identifier in route */ this.identifier = "id"; } /** * On init hook */ ngOnInit() { // Subscribe to URL params this.subscriber.register("params:change", this.route.paramMap.subscribe((params) => this.onDetail(params))); } /** * On destroy hook */ ngOnDestroy() { // Clear subscriptions this.subscriber.clear(); } /** * On detail hook * @param params */ onDetail(params) { return __awaiter(this, void 0, void 0, function* () { // Get detail yield this.get({ _id: params.get(this.identifier) }); }); } /** * Get entity * @param entity */ get(entity) { return __awaiter(this, void 0, void 0, function* () { // Get entity const validation = yield this.service.get({ _id: entity._id }); // Call on did get hook yield this.onDidGet(validation); }); } }