我正在寻找一种方法来执行以下操作:
我有一个主角应用程序,我想动态加载组件,这些组件将是远程的。某种程度上是一个插件系统
这样的事情可能吗?我可以从休息电话中获取一个组件,比如json吗?
感谢您的建议
答案 0 :(得分:-1)
试试这样:
<强> app.service.ts 强>
import { Injectable } from '@angular/core';
import { Http, Response } from '@angular/http';
import { Observable } from 'rxjs/Rx';
@Injectable()
export class AppService {
private resourceUrl = 'http://localhost:3002';
constructor(private http: Http) { }
getMethod() {
return this.http.get(resourceUrl)
.map(res => res.json());
}
}
<强> app.component.ts 强>
import { AppService } from './app.service';
export class DashboardComponent implements OnInit {
constructor(
private appService: AppService
) {
}
ngOnInit(){
this.appService.getMethod()
.subscribe(data => {
this.data = data;
});
}
}
<强> app.module.ts 强>
import { AppService } from './app.service';
@NgModule({
providers: [
AppService
],
})