【发布时间】:2016-10-10 09:29:54
【问题描述】:
我有 2 个组件。一个是页面,另一个是在页面上滑动的过渡。我希望将值传递给 transitionComponent 中的函数但无法弄清楚。@input 是最好的方法还是有另一种方法直接调用另一个组件中的函数?
使用代码示例编辑 - 我已经精简了主要组件,只专注于传递这个值:
父组件:
import {Component, ElementRef, OnInit} from '@angular/core';
import {TransitionComponent} from '../../PageLoader/TransitionComponent';
@Component({
selector: 'home',
templateUrl: './app/components/Homepage/list/index.html',
directives: [ TransitionComponent]
})
export class HomepageListComponent implements OnInit {
transitionState: string;
constructor() {
this.transitionState = this.transitionState;
}
ngOnInit() {
this.transitionState = "test";
}
}
子组件:
import {Component, Input, OnInit} from '@angular/core';
@Component({
selector: 'the-loader',
template: `<div class="loader"></div>`,
styles: [`
.loader {
background-color: black;
height: 100%;
width:100%;
position:absolute;
top:0;
left:0;
z-index:99999;
}
`]
})
export class TransitionComponent {
@Input() transitionState;
transitionStatus(transitionState) {
alert(transitionState);
}
}
【问题讨论】:
标签: angular angular2-template angular2-directives