Angular 4.0.0找不到引导代码 [英] Angular 4.0.0 could not find bootstrap code

查看:96
本文介绍了Angular 4.0.0找不到引导代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

错误:试图查找引导程序代码,但指定可静态分析的引导程序代码,或将entryModule传递给插件选项.

Error : Tried to find bootstrap code, but Specify either statically analyzable bootstrap code or pass in an entryModule to the plugins options.

main.ts

getHttp().get('/assets/config.json').toPromise()
 .then((res: Response) => {
 let conf = res.json();
 platformBrowserDynamic().bootstrapModule(createAppModule(conf));
})

我正在使用angular-cli. 在angular v2.3.1中,此代码可以正常工作.

I am using angular-cli. With angular v2.3.1 this code was working fine.

我想获取json并将其传递给@Ngmodules提供程序

I want to fetch json and pass it to @Ngmodules providers

{ provide: Config, useValue: conf } 

推荐答案

如果您要从config.json获取的数据仅是应用程序模块的配置,并且您正在尝试创建Config服务来存储它们,我认为最好是将其分配给environment并稍后在您的Config服务中读取它. environmentmain.ts中可用,因此不需要黑客入侵(createAppModule).

If the data you are fetching from config.json are just about a configuration of an application module and you are trying to create a Config service to store them, I think the best would be to assign it to the environment and read it in your Config service later. The environment is available in main.ts, so no hacking (createAppModule) needed.

import { environment } from './environments/environment';
import { AppModule } from './app/';

getHttp().get('/assets/config.json').toPromise()
   .then((res: Response) => {
       let conf = res.json();
       environment.settings = conf;
       platformBrowserDynamic().bootstrapModule(AppModule);
});

还必须在src/environments/environment.ts文件中声明environment的所有新属性.

You must also declare all new properties of environment in your src/environments/environment.ts file.

这篇关于Angular 4.0.0找不到引导代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆