Type checking in Angular 2 templates

后端 未结 7 809
夕颜
夕颜 2021-02-02 06:07

We are building an application in Angular 2 and TypeScript. We try to statically check types where it is possible. Is there any way to check types in templates? Consider the fol

7条回答
  •  忘掉有多难
    2021-02-02 06:22

    to quote the official statement:

    In the template type-checking phase, the Angular template compiler uses the TypeScript compiler to validate the binding expressions in templates.

    Template validation produces error messages when a type error is detected in a template binding expression, similar to how type errors are reported by the TypeScript compiler against code in a .ts file.

    More at:

    Angular Template checking https://angular.io/guide/aot-compiler#binding-expression-validation

    Yet to activate it, you should build the app, by

    ng build --aot
    

    or

    ng build --prod

    but you can also activate it without building:

    ng serve --aot

提交回复
热议问题