小编sha*_*552的帖子

角度@Output 不起作用

尝试与@Output 事件发射器进行子级与父级通信,但这里不起作用的是子组件

import { Component, OnInit, Output, Input, EventEmitter } from '@angular/core';

@Component({
  selector: 'app-emiter',
  templateUrl: './emiter.component.html',
  styleUrls: ['./emiter.component.css']
})
export class EmiterComponent implements OnInit {

@Output() emitor: EventEmitter<any>
  constructor() { this.emitor = new EventEmitter()}

   touchHere(){this.emitor.emit('Should Work');
   console.log('<><><><>',this.emitor) // this comes empty
  }

  ngOnInit() {
  }

}
Run Code Online (Sandbox Code Playgroud)

这是 html 模板

<p>
<button (click)=" touchHere()" class="btn btn-success btn-block">touch</button>
</p>
Run Code Online (Sandbox Code Playgroud)

touchHere 中的 console.log 即使我把它放在父组件中它也没有显示任何内容它也没有显示父组件

 import { Component , OnInit} from '@angular/core';
// service I use for other stuff//
    import { SenderService } …
Run Code Online (Sandbox Code Playgroud)

javascript angular-components angular

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

angular ×1

angular-components ×1

javascript ×1