0
A
回答
-1
这里是如何实现这种方式。
MainComponent.ts
import { Component } from '@angular/core';
import { MyService1 } from '../../providers/myService1/myService1';
import { MyCmp1 } from '../../components/myCmp1/myCmp1';
@Component({
templateUrl: 'build/pages/mainComponent/mainComponent.html',
providers: [
MyService1
],
directives: [
MyCmp1
],
//pipes: [ ... ] // Pipes which you are using
})
export class MainComponent {
main: any;
constructor() {
this.load();
}
load(): void {
MyService1.loadData()
.then((response) => {
main.data1 = response;
});
}
onShowMe(data): void {
alert(data);
}
}
MainComponent.html
<div class="main-component">
<h1>Main Component</h1>
<my-cmp-1 [data1]="main?.data1" (onShowMe)="onShowMe($event)"></my-cmp-1>
</div>
MyCmp1.ts
import { Component, EventEmitter } from '@angular/core';
import { Input, Output } from '@angular/core';
@Component({
selector: 'my-cmp-1',
templateUrl: 'build/components/myCmp1/myCmp1.html'
})
export class MyCmp1 {
@Input() data1: any;
@Output() onShowMe = new EventEmitter();
showMe(event: Event, data: any): void {
event.preventDefault(); // If you are using <a> or etc.
this.onShowMe.emit(data);
}
}
MyCmp1.html
<h3>My Component 1</h3>
<a href="" (click)="showMe($event, 'message from MyCmp1')">Show Me</a>
相关问题
- 1. Angular2将组件注入其他组件
- 2. Angular2创建组件
- 3. 如何创建列出其他组件的组件属性?
- 4. 如何从Angular2中的其他组件调用组件中的函数?
- 5. Angular2。动态组件创建
- 6. 从其他组件的事件创建组件
- 7. 在Angular2中创建链接组件
- 8. Nativescript angular2重用组件在其他组件
- 9. 如何根据React JS中的其他组件创建Dropdown组件?
- 10. 组件如何提供其他组件?
- 11. React Native - 如何在其他组件上创建和渲染组件
- 12. 动态地angular2任何事件在其他组件
- 13. 如何创建从少数其他组件继承的Delphi组件?
- 14. 从组件发送数据到其他组件Angular2
- 15. Angular2 Reactive Form - 其他组件中的表单控件
- 16. 如何在Angular2中动态创建SVG组件?
- 17. 如何在React中创建Toast等全局组件并将其引用到其他组件中?
- 18. 如何在其他组件中使用家庭组件数据?
- 19. 动态创建ng-content的angular2组件
- 20. cycle.js - 嵌入组件在其他组件
- 21. 如何使用HttpResponse或其他内容创建组件的动态http响应
- 22. [angular2] [ngModules]如何从其他模块调用组件?
- 23. Joomla如何从其他组件创建模型
- 24. Angular2 CLI Angular-Meteor组件创建
- 25. Angular2:动态组件创建:AOT编译
- 26. Angular2 @ViewChildren在其他组件中返回undefined
- 27. 如何在angular2中更新父组件的父组件
- 28. 创建由其他XML文件组成的XML布局文件?
- 29. Angular2中的组件
- 30. Angular2创建一个显示外部网页内容的组件