您的位置:首页 > Web前端 > AngularJS

Angular2-编写一个简易的组件

2017-06-04 23:59 253 查看
  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 {}


  同理,模板、指令、服务、管道也可以这么理解。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐