“private” and “public” in Angular component

前端 未结 2 1421
走了就别回头了
走了就别回头了 2020-12-12 15:43

If I don’t add private before foo, loadBar, andtext, I believe they are public by default.



        
2条回答
  •  遥遥无期
    2020-12-12 16:11

    @drewmoore provides a good answer in that private/public boils down to intent. But there are a few more things to consider when using injected private values:

    • Both typescript (noUnusedLocals) and tslint (no-unused-variable) will report errors if you use @Import() private foo, or constructor(private foo) {}, and only use foo in your template
    • AOT wont work:

    If we want to emit TypeScript as output of the AoT compilation process we must make sure we access only public fields in the templates of our components**

    • It is considered an anti-pattern

提交回复
热议问题