@hicoder/angular-cli
Version:
Angular UI componenets and service generator. It works with the mean-rest-express package to generate the end to end web application. The input to this generator is the Mongoose schema defined for the express application. mean-rest-express exposes the Res
72 lines (63 loc) • 2.63 kB
text/typescript
import { Component, OnInit, AfterViewInit, Input, Output, EventEmitter } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Injector } from '@angular/core';
import { <%-SchemaName%>DetailCustComponent } from '../../../<%-moduleName%>-cust/base/<%-schemaName%>/<%-schemaName%>-detail.cust.component';
import { ViewType } from '../<%-schemaName%>.component';
import { <%-SchemaName%>Service } from '../<%-schemaName%>.service';
<%if (referred) {%>
import { ViewChild, ViewContainerRef } from '@angular/core';<%}%><%
let refListSubs = [];
if (referred) {
for (let ref of referredBy) {
let refApi = ref[8];
let refName = ref[10];
if (detailRefBlackList && detailRefBlackList.includes(refName)) {
continue;
}
if (refApi.includes("L")) {
refListSubs.push([ref[0],ref[1]]);
}
}
}%><% for (let ref of refListSubs) {%>
import { <%-ref[1]%>ListSubComponent } from '../../<%-ref[0]%>/<%-ref[0]%>-list/<%-ref[0]%>-list-sub.component';<%}%>
({
template: '',
})
export class <%-SchemaName%>DetailComponent extends <%-SchemaName%>DetailCustComponent implements OnInit, AfterViewInit {
public override view: ViewType = ViewType.DETAIL;
<%if (referred) {%>
public override referredByComponents: { [k: string]: any } = {<% for (let ref of refListSubs) {%>
'<%-ref[0]%>': {'type': <%-ref[1]%>ListSubComponent, 'componentRef': null },<%}%>
}
('sublistContainer', { read: ViewContainerRef }) public override referredByRef?: ViewContainerRef;
<%}%>
constructor(
public override <%-schemaName%>Service: <%-SchemaName%>Service,
public override injector: Injector,
public override route: ActivatedRoute,
) {
super(<%-schemaName%>Service, injector, route);
<% let theView = detailView; let isEditView = false;%><%- include('schema-construct.component.ts', {theView: detailView, isEditView: false}) %>
}
override ngOnInit() {
super.ngOnInit();
let id = this.route.snapshot.paramMap.get('id');
if (!this.id) this.id = id? id : '';
if (this.id) {
this.populateDetail(this.id);
} else if (this.searchObj) {
// search item based on the unique value
this.populateDetailByFields(this.searchObj);
} else {
console.error("Routing error for detail view... no id...");
return;
}
}
ngAfterViewInit() {<% if (refListSubs.length > 0) {%>
//Load first reference, if not others activated
if (!this.options['disableRefLink'] && !this.referredByOpened) {
setTimeout(()=>{this.onReferredClicked('<%-refListSubs[0][0]%>');}, 50);
}
<%}%>
}
}