【发布时间】:2020-03-14 05:00:03
【问题描述】:
我想将来自child-information 组件的age 输入的数据发送到包含垂直线的组件age-line。当它到达年龄时,这条线向左移动'age * 100 pixels'。
我的代码有什么问题?没有错误消息。
Child-inf.html:
<button id="okButton" (click)=addAge()>OK</button>
Age : <input
type="text" name="Age" value="Kor" id="ageId" onfocus="this.value =
this.value=='Kor'?'':this.value;" onblur="this.value =
this.value==''?'Kor':this.value;">
子-inf.ts:
export class ChildInformationsComponent implements OnInit {
age:number = 1;
@Output() buttonClicked: EventEmitter<number> = new EventEmitter<number>();
constructor(private el: ElementRef) { }
ngOnInit() { }
addAge(){
this.age =parseInt((<HTMLInputElement>document.getElementById('ageId')).value);
this.buttonClicked.emit(this.age);
}
}
年龄线html:
<div class="age-line" [style.left.px]="age * 100"> <div class="line"></div> </div>
年龄线 ts:
export class AgeLineComponent implements OnInit {
constructor() { }
age: number= 1;
showNextComponent(emittedAge: number) {
this.age = emittedAge;
console.log('Button clicked');
}
ngOnInit() { }
}
【问题讨论】:
-
年龄行没有属性
(buttonClicked),它存在于Child-inf -
发布包含年龄线和子选择器的父 html
-
bro 0 * n = 0. 所以初始化 age: number = 1
-
还是不行:(
标签: css angular output eventemitter pass-data