AfterContentInit, AfterContentChecked, OnDestroy钩子

本文探讨Angular中组件的AfterContentInit和AfterContentChecked生命周期钩子,以及OnDestroy钩子。从app-routing模块到组件模板(HTML)和 TypeScript 实现,逐一解析这些钩子在不同阶段的作用,如何监听内容变化和在组件销毁时释放资源。
摘要由CSDN通过智能技术生成

app-routing TS

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import {NextlinkComponent} from './nextlink/nextlink.component';
import {ChildComponent} from './child/child.component';

const routes: Routes = [
  {path: '', component: ChildComponent},
  {path: 'nextlink', component: NextlinkComponent},
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule { }

app HTML

<div class="wrapper">
  <h2>我是父组件</h2>
  <div>这个div定义在父组件中</div>
  <app-child>
    <div class="header">这个div是父组件投影到子组件的1, {
  {title}}</div>
    <div class="footer">这个div是父组件投影到子组件的2</div>
  </app-child>
</div>
<div [innerHTML] = 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值