Advertisement
TUrkel

Component

Oct 1st, 2017
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import {
  2.     Compiler, Component, ComponentRef, Injector, NgModule, NgModuleRef, ViewChild, ViewContainerRef
  3. } from '@angular/core';
  4. import { ActivatedRoute } from "@angular/router";
  5. import { FormsModule, NgForm } from "@angular/forms";
  6. import { HttpService } from './ht.service';
  7.  
  8. @Component({
  9.   selector: 'app-module-routing',
  10.   templateUrl: './module-routing.component.html'
  11. })
  12. export class ModuleRoutingComponent {
  13.  
  14.   @ViewChild('vc', {read: ViewContainerRef}) vc: ViewContainerRef;
  15.   private cmpRef: ComponentRef<any>;
  16.  
  17.   private module_name: string;
  18.   private module_link: any;
  19.  
  20.   private module_links = [
  21.         {"access": "salessalquoent", "link": "sales\/sales_order_entry.php?NewQuotation=Yes"},
  22.     ];
  23.  
  24.   constructor(private compiler: Compiler,
  25.                 private injector: Injector,
  26.                 private m: NgModuleRef<any>,
  27.                 private route: ActivatedRoute,
  28.                 private httpService: HttpService) {}
  29.  
  30.   test() { //<-- Want to Call this function
  31.       alert('function called successfully');
  32.   }
  33.  
  34.   printPage(template, httpService, link) {
  35.  
  36.       const styles = [`input { width: 100px, display: block }`];
  37.       const tmpCmp = Component({ template, styles }) (
  38.           class {
  39.               OnSubmit(form: NgForm) {
  40.                   console.log(form);
  41.  
  42.                   this.ModuleRoutingComponent.test(); //<-- Want to call Parent Component function here
  43.  
  44.                   httpService.getPage(link, form.value)
  45.                       .subscribe(
  46.                           data => this.instance.printPage(data, httpService, link)
  47.                       );
  48.                   return false;
  49.               };
  50.           }
  51.       );
  52.  
  53.       const tmpModule = NgModule({
  54.           imports: [FormsModule],
  55.           declarations: [tmpCmp]
  56.       })(class {});
  57.  
  58.       this.compiler.compileModuleAndAllComponentsAsync(tmpModule)
  59.           .then((factories) => {
  60.               const f = factories.componentFactories[0];
  61.               this.cmpRef = f.create(this.injector, [], null, this.m);
  62.               this.cmpRef.instance.name = 'someForm';
  63.               this.vc.insert(this.cmpRef.hostView);
  64.           });
  65.   }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement