Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 通过角度2中的组件传递值_Angular - Fatal编程技术网

Angular 通过角度2中的组件传递值

Angular 通过角度2中的组件传递值,angular,Angular,我正在使用Ng2Bs3ModalModule显示一个组件。为此,我采用以下方法: 我在主组件上创建一个模板,如下所示 <modal #modal> <modal-header [show-close]="true"> <h4 class="modal-title">Update Job Service</h4> </modal-header> <modal-body>

我正在使用Ng2Bs3ModalModule显示一个组件。为此,我采用以下方法:

我在主组件上创建一个模板,如下所示

<modal #modal>
    <modal-header [show-close]="true">
        <h4 class="modal-title">Update Job Service</h4>
    </modal-header>
    <modal-body>
        <app-job-service-edit></app-job-service-edit>
    </modal-body>
</modal>

更新作业服务
此后,我在(单击)事件中使用以下model.open()打开此模型

编辑
现在我需要通过单击上面的按钮向组件传递一个值。我该怎么做


提前谢谢

您可以使用另一个函数调用来使用半列发送值

(单击)=“model.open();(单击)=“test('hello')

<button type="button" class="flat btn-danger" name="table_records"  (click)="modal.open();(click)="test('hello')">EDIT</button>

您可以使用半列,并将值设置为范围<代码>编辑
模态组件可以直接访问主组件,无需通过。请在@nifCody上检查我的答案,请检查我的答案。
<button type="button" class="flat btn-danger" name="table_records"  (click)="modal.open();(click)="test('hello')">EDIT</button>
import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  styles: [`
    .app {
      display: block;
      text-align: center;
      padding: 25px;
      background: #f5f5f5;
    }
  `],
  template: `
    <div class="app">
       <a (click)="test('hello')">Click me to alert</a>
    </div>
  `
})
export class AppComponent {


  test(value): void {
  console.log(value)
  alert(value)
}

}