首页 > 其他 > 详细

angular ngIf指令 以及组件的输入输出

时间:2019-12-05 16:07:57      阅读:111      评论:0      收藏:0      [点我收藏+]

ngIf 指令

技术分享图片

 

<span *ngIf="i === selectedIndex" class="botStyle"></span>

 

组件的输入输出

技术分享图片

 

子组件:

 

 

import { Component, OnInit, Input, Output, EventEmitter } from ‘@angular/core‘;   //eventEmitter  不要导错


export interface TopMenu {
  title: string;
  link: string;
}

@Component({
  selector: ‘app-scroll-table-tab‘,
  templateUrl: ‘./scroll-table-tab.component.html‘,
  styleUrls: [‘./scroll-table-tab.component.css‘]
})
export class ScrollTableTabComponent implements OnInit {
  selectedIndex = -1;
  @Input() menus: TopMenu[] = [];
  @Output() tabSelected = new EventEmitter();
  constructor() { }

  ngOnInit() {
  }
  handleSelection(index: number){
    this.selectedIndex = index;
    this.tabSelected.emit(this.menus[this.selectedIndex]);
  }
}

父组件:

HTML
<app-scroll-table-tab [menus]="topMenus" //子组件menus 通过@Input 接收父组件的topMenus (tabSelected)="handleTabSelected($event)" //父组件通过 @Output tabSelected 把子组件menus中点击的index 接收 ></app-scroll-table-tab>

JS
  handleTabSelected(TopMenu: TopMenu){
      console.log(TopMenu);
   }

 

 

 

angular ngIf指令 以及组件的输入输出

原文:https://www.cnblogs.com/webmc/p/11989416.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!