Angular ng build --target=production 给出错误

Angular ng build --target=production giving errors

我使用 Angular-CLI 创建了一个新的 Angular 项目。

我使用的版本是:

Angular-Cli: 1.0.2

Angular: 4.0.0.

我已经在其中添加了很多代码,但是现在,当我使用以下命令构建我的项目时,出现了一堆错误

ng build --target=production --env=staging

错误:

/src/app/views/signup/signup.component.html (21,86): Property 'email' is protected and only accessible within class 'SignUpComponent' and its subclasses.

/src/app/views/signup/signup.component.html (26,80): Property 'password' is protected and only accessible within class 'SignUpComponent' and its subclasses.

有人可以在这方面帮助我,我怎样才能消除这些错误?当我省略 --target=production 时构建成功但是在过去我遇到了一个问题,即没有指定目标浏览器缓存旧部署版本并且用户必须删除浏览器缓存才能生效最新 changes/deployment.

您的电子邮件和密码属性是否定义为私人的?它们是否用于组件的模板中?然后需要将它们从 private 更改为 public.

当您使用 Angular CLI 的生产模式时,您会自动获得以下信息:

  • --aot 设置为真
  • --output-hashing设置为全部(指纹资产)
  • --sourcemaps 设置为 false
  • --extract-css 设置为 true(为全局样式制作真实的 css 文件,而开发人员制作 .js 文件作为重建优化)
  • 如果在 CLI 中配置,则添加 service worker json
  • production 值替换模块中的 process.env.NODE_ENV(这对于一些库是必需的,比如反应)
  • 在代码上运行 uglify

有关详细信息,请参阅此内容:https://github.com/angular/angular-cli/pull/6232

最有可能产生这些错误的是 aot 编译器。 aot 编译器在 TypeScript 中编译模板,因此会产生更多类型错误。所以另一种选择是使用不带 aot 的 --prod

你云尝试设置 public 电子邮件和密码的可见性。