Angular2组件可以这么理解:编写一个类,然后在类的上面用组件装饰器装饰一下,这个类就成组件了。

  所以编写组件分两步:1)编写类;2)编写装饰器

  1)编写类:

export class SimpleComponent {}

  2)在类上面编写装饰器:

@Component({
   selector: 'simple-component',
   template: `Hello Simple Component!`  
})

  完整代码如下:

@Component({
   selector: 'simple-component',
   template: `Hello Simple Component!`  
})
export class SimpleComponent {}

  同理,模板、指令、服务、管道也可以这么理解。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-08-23
  • 2022-12-31
  • 2022-12-23
  • 2021-09-08
  • 2022-01-15
  • 2021-11-21
猜你喜欢
  • 2022-12-23
  • 2021-09-08
  • 2021-05-26
  • 2021-10-17
  • 2021-07-07
  • 2019-11-10
相关资源
相似解决方案