angular 中如何使用自定义组件
2024-08-28 20:19:58
1.创建header组件
ng g component components/header
header.component.ts
import { Component, OnInit } from '@angular/core'; /*引入 angular 核心*/ @Component({
selector: 'app-header', /*使用这个组件的名称*/
templateUrl: './header.component.html', /*html 模板*/
styleUrls: ['./header.component.scss'] /*css 样式*/
})
export class HeaderComponent implements OnInit { /*实现接口*/ constructor() { }/*构造函数*/ ngOnInit() {/*初始化加载的生命周期函数*/
} }
2.在使用的地方使用组件
比如在跟组件下使用
<!--The content below is only a placeholder and can be replaced.-->
<div style="text-align:center"> <h1>
Welcome to {{ title }}
</h1>
</div>
<app-header></app-header>
<router-outlet></router-outlet>
最新文章
- android微信分享不出去?四步搞定!
- 从零开始编写自己的C#框架(3)——开发规范
- 【原】PHP初体验
- Nutch源码阅读进程3---fetch
- 【C语言】二维指针做形参
- Spring —— 三种配置数据源的方式:spring内置、c3p0、dbcp
- Hadoop 一二事(1) - 简单介绍与杂谈
- android 项目学习随笔八(xUtils的BitmapUtils模块)
- Centos yum 安装mysql报错 No package mysql-server available.
- Python 通用爬虫 和讯博客 scrapy
- JAVA中的配置文件XML
- HashMap的源码分析
- 8.6 正睿暑期集训营 Day3
- ubuntu 18.04下安装Java
- Windows Service 之 Bug 记录
- Retrofit2完全教程
- shell中的环境变量:local,global,export
- Python学习-28.Python中的列表切片
- Qt信号槽的一些事
- 基数排序算法-python实现
热门文章
- kali linux tools
- 理解serverless无服务
- SpringBoot配置HTTPS,并实现HTTP访问自动转HTTPS访问
- Codeforces Round #511 (Div. 2) C. Enlarge GCD (质因数)
- Android加载大图到内存如何避免内存溢出?
- [GraphQL] Query Lists of Multiple Types using a Union in GraphQL
- GridView修改含有DropDownList控件列的宽度
- 使用webuploader实现大文件传输
- 洛谷P1006 传纸条(多维DP)
- tesonflow实现word2Vec