Angular2-编写一个简易的组件

Posted 乐小天

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Angular2-编写一个简易的组件相关的知识,希望对你有一定的参考价值。

  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 {}

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

以上是关于Angular2-编写一个简易的组件的主要内容,如果未能解决你的问题,请参考以下文章