Giter VIP home page Giter VIP logo

Comments (2)

Razgort avatar Razgort commented on August 15, 2024

I add you here the modified files

import { Observable } from 'rxjs';
import { ModuleData } from './../models/module.model';
import { Http } from '@angular/http';
import {
HttpClientModule,
HttpClient,
HTTP_INTERCEPTORS
} from '@angular/common/http';

import { Injectable, Compiler, Inject, ReflectiveInjector, Injector, COMPILER_OPTIONS } from '@angular/core';

import { map } from 'rxjs/operators'

// Needed for the new modules
import * as AngularCore from '@angular/core';
import * as AngularCommon from '@angular/common';
import * as AngularRouter from '@angular/router';
import * as AngularClarity from '@clr/angular';
import * as BrowserAnimations from '@angular/platform-browser/animations';

declare var SystemJS: any;

@Injectable()
export class ModuleService {
source = http://${window.location.host}/;

constructor(private compiler: Compiler, private http: Http) {
    console.log(compiler);
}

loadModules(): Observable<ModuleData[]> {
    return this.http.get("./assets/plugins/modules.json")
        .pipe(map(res => res.json()));
}

loadModule(moduleInfo: ModuleData): Observable<any> {
    let url = this.source + moduleInfo.location;
    return this.http.get(url)
    .pipe(
        map(res => res.text()),
        map(source => {
            const exports = {}; // this will hold module exports
            const modules = {   // this is the list of modules accessible by plugins
                '@angular/core': AngularCore,
                '@angular/common': AngularCommon,
                '@angular/router': AngularRouter,
                '@angular/platform-browser/animations': BrowserAnimations,
                '@clr/angular': AngularClarity
            };


            // shim 'require' and eval
            const require: any = (module) => modules[module];
            eval(source);

            // Need to check if there is another solution for eval as this is described as 'Evil'

            this.compiler.compileModuleAndAllComponentsSync(exports[`${moduleInfo.moduleName}`])
            //console.log(exports); // disabled as this object is cleared anyway
            return exports;
        })
        )
        ;
}

loadModuleSystemJS(moduleInfo: ModuleData): Promise<any> {
    let url = this.source + moduleInfo.location;
    SystemJS.set('@angular/core', SystemJS.newModule(AngularCore));
    SystemJS.set('@angular/common', SystemJS.newModule(AngularCommon));
    SystemJS.set('@angular/router', SystemJS.newModule(AngularRouter));
    SystemJS.set('@angular/platform-browser/animations', SystemJS.newModule(BrowserAnimations));
    SystemJS.set('@clr/angular', SystemJS.newModule(AngularClarity));

    // now, import the new module
    return SystemJS.import(`${url}`).then((module) => {
        console.log(module);
        return this.compiler.compileModuleAndAllComponentsAsync(module[`${moduleInfo.moduleName}`]).then(compiled => {
            console.log(compiled);
            return module;
        });
    });
}

}

from angular-umd-dynamic-example.

lmeijdam avatar lmeijdam commented on August 15, 2024

already had 1 on 1 contact with user! solved it!

from angular-umd-dynamic-example.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.