1
我認爲這個問題在我的示例中很簡單,因爲當我引用名稱時,所有內容都可以正常工作,但當我嘗試使用自定義短名稱名。無法在@Input()@Output中使用自定義名稱與Ionic 3和Angular
當我在裝飾器中使用自定義名稱時,我有一個完整的百分比組件移動工作條,當我引用內部字段PercentComplete時,它工作正常。
我的組件:
import { Component, Input, Output, EventEmitter } from '@angular/core';
@Component({
selector: 'progress-bar',
templateUrl: 'progress-bar.html'
})
export class ProgressBarComponent {
@Input() // @Input('Percent') does not work
PercentComplete: number = 0;
@Output()
PercentChange: EventEmitter<number> = new EventEmitter<number>();
constructor() { }
Increment() {
this.PercentComplete ++;
this.PercentChange.emit(this.PercentComplete);
}
}
簡單的HTML頭
<ion-header>
<ion-toolbar color="light" mode="md">
<progress-bar [PercentComplete]="15"></progress-bar>
</ion-toolbar>
</ion-header>
組件的HTML:
<div class="progress-outer">
<div class="progress-inner" [style.width]="PercentComplete + '%'">
{{PercentComplete}}%
</div>
</div>
<div>
<button ion-button round (click)="Increment()">
<ion-icon name="add-circle"> </ion-icon>
</button>
</div>
如果我改變從PERCENTCOMPLETE所有HTML引用僅僅是百分比,那麼它不起作用。