如何强制开发模式不存在的属性的角度输出错误?

时间:2018-06-15 11:27:52

标签: angular angular5 typescript2.0

我有一个通过Angular CLI生成的Angular 5应用程序。假设我有一个包含以下标记的组件:

<div *ngIf="dummyShowProp">
    <!-- other stuff here -->
</div>

开发模式

ng serve --hmr

如果组件定义dummyShowProp,它可以正常工作。如果组件未定义属性,则不显示div并且未发出错误(我假设未声明的属性被评估为falsy

生产构建

ng build --prod

此操作失败(正确IMO),并出现以下错误:

  

错误my.component.html(2,6)::属性'dummyShowProp'没有   存在于'MyComponent'类型上。

生产模式比开发模式更严格,但我无法在开发模式下找到如何强制进行此检查。

以下相关配置:

的package.json

  "devDependencies": {
    "@angular/cli": "~1.7.4",
    "@angular/compiler-cli": "^5.2.0",
    "@angular/language-service": "^5.2.0",
    "@angularclass/hmr": "^2.1.3",
    "@types/jasmine": "~2.8.3",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "~6.0.60",
    "codelyzer": "^4.0.1",
    "jasmine-core": "~2.8.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~2.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.2",
    "ts-node": "~4.1.0",
    "tslint": "~5.9.1",
    "typescript": "~2.5.3"
  }

tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2017",
      "dom"
    ]
  }
}

问题:如何强制开发模式不存在的属性的角度输出错误?

1 个答案:

答案 0 :(得分:0)

使用命令app/src/main/res/values/strings.xml

使用ng build --env=prod您无法实现AOT编译,有关详细信息,请参阅文档:https://github.com/angular/angular-cli/wiki/build#build-targets-and-environment-files