简体   繁体   English

Angular 2 AOT构建-需求问题

[英]Angular 2 aot build - require issue

When building my application aot via angular-cli 通过angular-cli构建我的应用程序时

ie (ng build --aot --prod) (ng build --aot --prod)

I am receiving the following error: 我收到以下错误:

..app>ng build --prod --aot
10% building modules 2/2 modules 0 active Error encountered 
resolving symbol values statically. Calling function 'require',
function calls are not supported. Consider replacing the function
or lambda with a reference to an exported function, resolving symbol
appComponent in ..app.component.ts, resolving symbol AppComponent 
in ..app.component.ts

My component looks like: 我的组件看起来像:

@Component({
selector: 'app-component',
template: `
 ...
<div class="centered">
    <img [src]="logo">
</div>
....
`,
styles: [require('./app-component.component.css')]
})

export class LoginComponent {

private logo = require('./logo.png');
...
}

Is there any workaround available? 有没有解决方法?

I do not think require statements are allowed with AOT compilation. 我认为AOT编译不允许使用require语句。 They're unnecessary anyways. 无论如何,它们都是不必要的。

Make this changes so the path is absolute to the application root 进行更改,以便路径是应用程序根目录的绝对路径

The component's template: 组件的模板:

<div class="centered">
    <img src="{{logo}}">
</div>

The component's class: 组件的类:

private logo = '/images/logo.png';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM