Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

为什么 Angular 2 中@Component 的selector是可选的 #51

Open
dreambo8563 opened this issue Jan 22, 2016 · 1 comment
Open

为什么 Angular 2 中@Component 的selector是可选的 #51

dreambo8563 opened this issue Jan 22, 2016 · 1 comment

Comments

@dreambo8563
Copy link

这是directive 的,component的应该也差不多吧
这里面所有参数都是optional的。
就是说 你可以new一个空指令,或者空组件。但意义何在呢?

难道是为了继承?

constructor({selector, inputs, outputs, properties, events, host, bindings, providers, exportAs,
             queries}?: {
  selector?: string,
  inputs?: string[],
  outputs?: string[],
  properties?: string[],
  events?: string[],
  host?: {[key: string]: string},
  providers?: any[],
  /** @deprecated */ bindings?: any[],
  exportAs?: string,
  queries?: {[key: string]: any}
})
@kittencup kittencup changed the title 关于指令构造中的可选参数 为什么 Angular 2 中@Component 的selector是可选的 Jan 22, 2016
@kittencup
Copy link
Owner

@component中的selector主要用来是匹配HTML中的自定义标签,使自定义标签实现组件的功能。
但是在非directive形式加载组件时,比如使用DynamicComponentLoader加载或者使用路由来加载,selector其实可以不需要(这种情况不写selector是不会报错的)。

在beta0的angular2,如果不写的话selector则为undefined,会创建一个undefined的标签,当然这个问题官方已经计划在下一版修正掉,如果你不写selector,默认会使用一个div标签,具体可看 angular/angular#1662 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants