레이블에 대한 입력을 변경하려고했지만 값에 오류가 발생합니다.
이것은 내 코드입니다
이것은 html입니다
<div class="row">
<div class="small-6 columns">
<label>Edad</label>
</div>
<div class="small-2 columns">
<input readonly type="text" [value]="CalculateAge()">
</div>
</div>
이것이 당신이 인감에 의해 어떻게 바뀌 었는지?
<div class="small-6 columns">
<label readonly for="text" [value]="CalculateAge()">
</label>
</div>
이것은 구성 요소입니다
export class DatosPersonalesComponent implements OnInit {
@Input()
datosDTO: DatosDTO;
public age: number;
constructor() {}
ngOnInit() {
this.datosDTO = new DatosDTO();
}
CalculateAge(): void {
if (this.datosDTO.datosPersonales.fechaNacimiento) {
var timeDiff = Math.abs(Date.now() - this.datosDTO.datosPersonales.fechaNacimiento);
this.age = Math.ceil((timeDiff / (1000 * 3600 * 24)) / 365);
}
}
}
도움을 주셔서 대단히 감사합니다.
label 은 일반적으로 for
속성과 함께 사용됩니다.
<label for="age">{{ age }}</label>
<input type="text" id="age">
값은 value
속성이 아닌 태그 사이에 있어야합니다.
get age(){
if (this.datosDTO.datosPersonales.fechaNacimiento) {
var timeDiff = Math.abs(Date.now() - this.datosDTO.datosPersonales.fechaNacimiento);
return Math.ceil((timeDiff / (1000 * 3600 * 24)) / 365);
}
}
클래스 내부의 함수는 일반적으로 대문자로 표기하지 않아야합니다.
calculateAge()
아직에서 초기화하도록 지정 datosDTO
하고 @Input()
있습니다 ngOnInit()
. 그렇게해서는 안됩니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다