加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

AoT NGC / Angular2:属性受到保护,只能在类Error中访问

发布时间:2020-12-17 10:18:45 所属栏目:安全 来源:网络整理
导读:在我使用的Angular 2 / Ionic 2(final / rc0)项目中的组件中: protected contentTarget: ViewContainerRef;ngOnInit() { this.contentTarget.createComponent(componentFactory); } AoT编译器说: Error at ....: Property 'contentTarget' is protected an
在我使用的Angular 2 / Ionic 2(final / rc0)项目中的组件中:
protected contentTarget: ViewContainerRef;

ngOnInit() {
        this.contentTarget.createComponent(componentFactory);
    }

AoT编译器说:

Error at ....: Property 'contentTarget' is protected and only accessible within class 'IncludeTemplateComponent' and its subclasses.

变量(属性)不会在整个项目中的任何其他位置使用.

那么……任何人都可以对此有所了解,是createComponent工厂将contentTarget变量传递给它的子节点,或者为什么编译器不喜欢这里受保护?现在所有Angular2中的受保护变量都是“被禁止的”吗?

从 here起

For a given component all its members (methods,properties) accessed
by its template must be public in the ahead-of-time 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.

我的看法是,contentTarget由模板引擎使用,因此,AOT必须公开才能工作.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读