2017-05-22 91 views
0

我看到很多問題,看起來像重複,但我沒有看到我需要從他們。ng禁用按鈕功能永遠不會被調用

所以我有一個角狀的部件:

@Component({ 
providers: [ 
FlowsheetService, 
SubscriptionService 
], 
moduleId: module.id, 
selector: 'flowsheet', 
templateUrl: './flowsheet.component.html', 
styleUrls: ['i-o-renderer.css'], 
encapsulation: ViewEncapsulation.None 
}) 

它實現了一個返回boolean值的公共職能。

public ableToRetrieveHistoricalData() { 
    return true; 
} 

上述函數永遠不會被調用,但按鈕點擊函數被調用。

的HML頁:

<div> 
    <div style="height: 10%; padding: 10px;"> 
     <span style="padding-left: 50px;"> 
       <button (click)="retrieveHistoricalData()" ng-disabled="ableToRetrieveHistoricalData()"> << Previous</button> 
     </span> 
    </div> 

</div> 

任何明顯我缺少什麼?

回答

1

如果您使用Angular2 +,請使用[disabled]而不是ng-disabled

<button (click)="retrieveHistoricalData()" 
[disabled]="ableToRetrieveHistoricalData()"> << Previous</button> 
0

是< <以前真的在HTML嗎?如果是這樣,我懷疑這是令人困惑的Angular。我會嘗試刪除< <以查看是否屬於這種情況。

0

我想你忘了,你是在angular2應用程序,你應該使用[disabled],而不是ng-disabled這是在angular1版本

<button (click)="retrieveHistoricalData()" [disabled]="ableToRetrieveHistoricalData()"> Previous</button> 

DEMO

使用
相關問題