角度2:组件中私有属性和公共属性之间的确切区别是什么? [英] Angular 2: What is the exact difference between private and public attributes in components?

查看:98
本文介绍了角度2:组件中私有属性和公共属性之间的确切区别是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以解释Angular 2组件中的private和not private属性之间的区别吗?类似于本示例中的private_textother_text:

Could someone explain the difference between private and not private attributes in components in Angular 2? Like with private_text and other_text in this example:

import { Component } from '@angular/core';

@Component({
  moduleId: module.id,
  selector: 'my-component',
  template: '<div>{{private_text}}</div><div>{{other_text}}</div>'
})
export class MyComponent {

  private private_text:string;
  other_text:string;

  constructor() {
    this.private_text = "hello";
    this.other_text = "hello";
  }

}

推荐答案

privatepublic是只有静态分析TypeScript代码的工具才能使用.

private and public is something that is only utilized by tools that statically analyze TypeScript code.

在运行时,私有和公共毫无意义,因为JS不了解它们.

At runtime private and public are meaningless because JS doesn't know about them.

TypeScript工具也不会检查模板字符串中是否存在可能违反TypeScript规则的绑定表达式.这就是对于模板来说,属性是私有的还是公共的都无所谓的原因.

TypeScript tools also are not checking the template string for binding expressions that might violate TypeScript rules. This is the reason that it doesn't matter for the template whether the property is private or public.

据我所知,计划改进模板分析功能以识别各种错误.但这只是未来.

As far as I know it is planned to improve template analyzing functionality to recognize all kind of mistakes. But that's only the future.

这篇关于角度2:组件中私有属性和公共属性之间的确切区别是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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