Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
500 views
in Technique[技术] by (71.8m points)

plugins - Get and load a remote component/module in an angular 4.4 app

Here is what i'm trying de achieve : I want to create an app using "plugins", by plugins I mean :

Another angular component/module that could be deployed on a remote host and displayed in my app.

Looks like I can't do such thing with webpack directly and that I should use SystemJs to dynamically load a module.

Any advice would be welcome to use SystemJs and Webpack (ng cli), examples of how to call remote module and load them.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Yes, you need to add systemjs to your angular-cli and use it to load a module. Then you can use componentFactoryResolver to resolve the components you need in the module. To add systemjs to your project install it:

npm i systemjs

and the following into angular-cli.json:

"scripts": [
    "../node_modules/systemjs/dist/system.src.js"
],

Also add a link to scripts.js in the page :

This will load systemjs and it will available as a global object. You can then use it like this:

declare var SystemJS;

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  constructor() {
    SystemJS.load(...);
  }

For details how to use SystemJS to load a module see How to load dynamic external components into Angular application answer


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...