属性"X"是私有的,只能在类"xyzComponent"中访问 [英] Property 'X' is private and only accessible within class 'xyzComponent'

查看:75
本文介绍了属性"X"是私有的,只能在类"xyzComponent"中访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为此

I'm trying to build angular2 application for production for that I'm following this blog. After my ngc successful compilation when the tsc compilation takes place it generates below error shown in the image:

搜索了一段时间后,我发现了这个部分中的问题,可能是因为它为您提供了一个很好的主意,指出发生了什么问题. 基本上,当我们将变量设为私有时,我们会得到 错误:属性是私有的,并且只能在类中访问" .我不明白为什么会这样.

After searching for a while I found this blog which explains the problem in "The context property" section which I'm not able to understood properly may be it give some good idea to you that what's happening wrong. basically when we're making a variable private we're getting "ERROR: Property is private and only accessible within class". I'm not understanding why is it coming.

过去几天来,我们一直在努力解决这个问题,请为我们提供帮助.

Kindly help us as we're banging our head in this problem for past couple of days.

推荐答案

对于给定的组件,其模板访问的所有成员(方法,属性)在AOT编译方案中必须是公共的.这是由于将模板转换为TS类.生成的类和组件现在是2个单独的类,您不能跨类访问私有成员.

For a given component all its members (methods, properties) accessed by its template must be public in the AOT compilation scenario. This is due to the fact that a template is turned into a TS class. A generated class and a component are 2 separate classes now and you can't access private members cross-class.

简而言之:如果要使用提前编译,则无法访问模板中的私有成员.

In short: you can't access private members in your templates if you want to use ahead-of-time compilation.

为了获得更好的解释 https://github.com/angular/angular/issues/11422

这篇关于属性"X"是私有的,只能在类"xyzComponent"中访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆