Angular自定义组件创建步骤

1.创建组件class

自己创建一个.ts文件 Component装饰器(Decorator)用于指定class的用法 selector:选择器

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

//装饰器(Decorator)用于指定class的用法

@Component({

template:'

我的组件c01


',

//选择器

//[myTitle]就是当属性来用

//myc01当元素来用

selector:'myc01',

})

export class MyC01Component{

}

2.接下来需要在某一个模块中注册组件class

在一个app.modle.ts文件中注册

import { MyC01Component } from './myc01';

@NgModule({

declarations: [ //宣言,声明,宣

MyC01Component, //宣言声明完成

],

3.使用已经注册过的组件

在一个.html文件中使用

精彩内容

评论可见,请评论后查看内容,谢谢!!!
 您阅读本篇文章共花了: