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

瑞安网站设计wordpress 推广 插件

瑞安网站设计,wordpress 推广 插件,自己做的一个网站怎么赚钱,wordpress 文章数量chatgpt: 在 Angular 中#xff0c;ViewChild 是一个装饰器#xff0c;用于在组件类中获取对模板中子元素、指令或组件的引用。它允许你在组件类中访问模板中的特定元素#xff0c;以便可以直接操作或与其交互。 例如#xff0c;如果你在模板中有一个子组件或一个具有本地…chatgpt: 在 Angular 中ViewChild 是一个装饰器用于在组件类中获取对模板中子元素、指令或组件的引用。它允许你在组件类中访问模板中的特定元素以便可以直接操作或与其交互。 例如如果你在模板中有一个子组件或一个具有本地引用的元素你可以使用 ViewChild 装饰器在组件类中获取对该元素的引用。这样你就可以在组件类中调用该元素的方法、访问其属性或者订阅其事件。 这是一个简单的示例演示了如何在 Angular 组件中使用 ViewChild import { Component, ViewChild, ElementRef } from angular/core;Component({selector: app-example,template: div #myElementSome content/div }) export class ExampleComponent {ViewChild(myElement, { static: true }) myElementRef: ElementRef;ngAfterViewInit() {// 可以在这里访问和操作子元素console.log(this.myElementRef.nativeElement.textContent); // 获取子元素的文本内容this.myElementRef.nativeElement.style.color red; // 修改子元素的样式} }在这个例子中ViewChild 装饰器用于获取模板中带有 #myElement 本地引用的 div 元素的引用并在 ngAfterViewInit 生命周期钩子中对其进行操作。 需要注意的是ViewChild 装饰器接受一个选择器作为参数用于定位模板中的元素。在这里我们使用了 #myElement 选择器来获取对应的元素引用。 另外{ static: true } 是 ViewChild 的一个配置选项用于指定何时应该去查询视图中的元素。{ static: true } 表示在组件初始化时就会进行查询{ static: false } 表示在首次调用 ngAfterViewInit 生命周期钩子时进行查询。 Angular For Beginners - 25. ViewChild() 当使用 JavaScript 时可以使用 getElementById 来获取特定的 HTML 元素对象。但在 Angular 中并没有类似于 getElementById 的直接函数。相反Angular 提供了 ViewChild 这样的装饰器用于在组件类中获取模板中特定元素的引用从而实现类似的功能。 但是getElementById 的参数与 ViewChild 的参数有很大的不同。 不能传 html 标签或 css 选择器给 ViewChild传进 ViewChild 中的参数分以下 4 种 1. pokemon-list.compoment.html 增加一个 template ref #pokemonRef: tabletheadthName/ththIndex/th/theadtbodyapp-pokemon-detail#pokemonRef // new code*ngForlet pokemon of pokemons[detail]pokemon(remove)handleRemove($event)h1-----------------------/h1h2/h2h3/h3/app-pokemon-detail/tbody /table2. 多个孩子用 ViewChildren 单个用 ViewChild 。 ViewChild 只能在 View 渲染之后才能使用 pokemon-list.compoment.ts : 因为 ngAfterViewInit 继承了 AfterViewInit, 所以 PokemonListComponent 需要 implement AfterViewInit: export class PokemonListComponent implements OnInit, AfterViewInit {完整代码如下 import { AfterViewInit, Component, ElementRef, OnInit, ViewChild, ViewChildren } from angular/core; import { Pokemon } from src/app/models/pokemon; import { PokemonService } from src/app/services/pokemon.service;Component({selector: app-pokemon-list,templateUrl: ./pokemon-list.component.html,styleUrls: [./pokemon-list.component.css], }) export class PokemonListComponent implements OnInit, AfterViewInit {// pokemons!: Pokemon[];pokemons: Pokemon[] [];// 这里不是 ViewChild, 否则log 为 undefined// 而是 ViewChildren使用了 for 循环, 孩子数多于一个有3个。ViewChildren(pokemonRef) pokemonRef!: ElementRef;constructor(private pokemonService: PokemonService) {}// 新代码ngAfterViewInit(): void {// throw new Error(Method not implemented.);console.log(ngAfterViewInit begin)console.log(this.pokemonRef)console.log(ngAfterViewInit end)}handleRemove(event: Pokemon) {this.pokemons this.pokemons.filter((pokemon: Pokemon) {return pokemon.id ! event.id;});}ngOnInit(): void {// 填充 pokemons 属性// this.pokemons this.pokemonService.getPokemons();this.pokemonService.getPokemons().subscribe((data: Pokemon[]) {console.log(data);this.pokemons data;});} }3. web 页面
http://www.zqtcl.cn/news/132162/

相关文章:

  • 一级a做爰片免播放器网站扬中门户网
  • 舆情网站大全模板网站有哪些在哪里下载
  • 新网站关键词怎么优化深圳公司网站推广
  • 新加坡购物网站排名英文版wordpress安装
  • 哪个网站做ppt能赚钱企查查企业信息
  • 学校建设网站的意义wordpress 鸟
  • 一个ip做网站网站建设基础课件
  • 包装设计十大网站连云港网站建设开发
  • 川沙网站建设网站推广服务外包有哪些渠道
  • 哪些网站可以做招商广告手机怎么创网站免费
  • 换物网站为什么做不起来网站开发工具的功能包括
  • 引导式网站君和网站建设
  • 西柏坡门户网站建设规划书自己做照片书的网站
  • 做网站横幅的图片多大公司做自己的网站平台台
  • 百度网站建设工资给城市建设提议献策的网站
  • 如何进入网站管理页面维护网站需要多少钱
  • 深圳住房和城乡建设局网站阿里云学生免费服务器
  • 如何做的网站手机可以用吗绵阳优化网站排名
  • 营销网站建设大全wordpress wp_register
  • 公司做年审在哪个网站网络seo专员招聘
  • 宿州网站建设费用网站快速建设入门教程
  • 怎么自己做网站加盟网站建设意义模板
  • 网站开发怎样实现上传视频教程内容导购网站模板
  • 济南做网站建设的公司广告公司资质
  • 域名分类网站微擎 wordpress
  • 公司产品营销策划安徽seo
  • 网站 平均加载时间百度搜索竞价推广
  • 赛车网站开发淄博网站建设及托管
  • 过时的网站湖州公司网站建设
  • 环球设计网站网站建设的面试要求