当前位置: 首页 > news >正文

Angular引用控件类

说明:
angular 在一个控件类里面,引入另外一个控件类,这样做的好处,就是代码分离,当你一个页面存在多少类似于独立的界面时,可以使用这种方式,分离代码 更好维护程序
效果图:
在这里插入图片描述

step1:E:\projectcar\ajcar\ajnine\untitled4\src\app\app.routes.ts

import { Routes } from '@angular/router';import {ContentExampleComponent} from './content/content-example/content-example.component';export const routes: Routes = [{path:'content',component:ContentExampleComponent}
];

step2: E:\projectcar\ajcar\ajnine\untitled4\src\app\content\content-example\content-example.component.html

<div style="background: red"><div class="w-8/12 bg-blue-100 mx-auto mt-5"><a href="" routerLink="/content" class="ml-4 underline text-blue-500">Go to Component Concept</a><div><app-content-second><p>This content is coming from the Parent</p><ng-container card-title>This is content from <b>custom selector</b></ng-container><div ngProjectAs="card-name"><b>Content from ngProjectAs</b></div></app-content-second></div></div>
</div>

step3: E:\projectcar\ajcar\ajnine\untitled4\src\app\content\content-example\content-example.component.ts

import { Component } from '@angular/core';import { ContentSecondComponent } from "../content-second/content-second.component";
import {RouterLink} from '@angular/router';@Component({selector: 'app-content-example',standalone: true,imports: [ContentSecondComponent, RouterLink],templateUrl: './content-example.component.html',styleUrl: './content-example.component.css'
})
export class ContentExampleComponent {}

step4: E:\projectcar\ajcar\ajnine\untitled4\src\app\content\content-second\content-second.component.html

<div style="background: coral"><h1>This is the child content component</h1><p>Projected content will be shown below</p><hr class="border-t border-gray-300 mb-8" /><ng-content></ng-content><ng-content select="[card-title]"></ng-content><!-- for ng project as--><ng-content select="card-name"></ng-content><div><p>HostListener example. {{ label }}</p></div>
</div>

step5: E:\projectcar\ajcar\ajnine\untitled4\src\app\content\content-second\content-second.component.ts

import {Component, HostBinding, HostListener} from '@angular/core';@Component({selector: 'app-content-second',standalone: true,imports: [],templateUrl: './content-second.component.html',styleUrl: './content-second.component.css'
})
export class ContentSecondComponent {@HostBinding('attr.aria-valuenow')value: number = 0;public label?: string;@HostListener('click', ['$event'])updateValue(event: MouseEvent) {this.label = 'Child component has been clicked';}}

end

http://www.lryc.cn/news/477857.html

相关文章:

  • stm32 踩坑笔记
  • 文件上传和文件包含
  • [Unity Demo]从零开始制作空洞骑士Hollow Knight第十八集补充:制作空洞骑士独有的EventSystem和InputModule
  • yelp数据集上试验SVD,SVDPP,PMF,NMF 推荐算法
  • 计算机视觉常用数据集Cityscapes的介绍、下载、转为YOLO格式进行训练
  • Flink和Spark在实时计算方面有何异同
  • 纵然千万数据流逝,唯独vector长存
  • 【LeetCode】【算法】739. 每日温度
  • 2025年知识管理新方案:十款前沿知识库搭建工具详解
  • WebSocket实现消息实时推送
  • flink 内存配置(三):设置JobManager内存
  • 蓝桥杯 Python组-神奇闹钟(datetime库)
  • 解决阿里云三个月证书过期 免费SSL证书部署教程
  • VBA03-变量
  • docker-ce-stable‘ 下载元数据失败 : Cannot download repomd.xml: Cannot download
  • C中定义字符串有下列几种形式
  • 写一个小日历
  • 【数据库】elasticsearch
  • Rust 构建 TCP/UDP 网络服务
  • docker镜像文件导出导入
  • ViT面试知识点
  • ChatGPT 和 RAG(检索增强生成)的区别;ChatGPT 和 RAG 的联系
  • qt获取本机IP和定位
  • CodeQL学习笔记(5)-CodeQL for Java(AST、元数据、调用图)
  • 服装品牌零售业态融合中的创新发展:以开源 AI 智能名片 S2B2C 商城小程序为视角
  • 前端将网页转换为pdf并支持下载与上传
  • Android 依赖统一配置管理(Version Catalogs)
  • 如何为数据看板产品接入实时行情接口并展示行情
  • 数据结构 C/C++(实验一:线性表)
  • 使用WebStorm开发Vue3项目