我使用angularjs創建了一個簡單的按鈕。所以,在意見HTML代碼如下所示:使用此。在角度不起作用?
<div ng-controller="ButtonCtrl">
<button ng-click="ButtonCtrl.setIndex(1)">Create another bidding query</button>
<button ng-click="ButtonCtrl.setIndex(2)">Create another asking query</button>
<form ng-hide="ButtonCtrl.isSelected(1)">
<h4>Filling The Bidding Form</h4>
<fieldset class="form-group">
<textarea class="form-control" ></textarea>
</fieldset>
</form>
<div>
而且ButtonCtrl被定義爲controller.js
app.controller('ButtonCtrl', function($scope) {
this.index=0;
this.setIndex=function(setbutt){
this.index=setbutt;
};
this.isSelected=function(checkbutt){
return this.index===checkbutt;
};
});
但是,我沒有得到預期如下行爲。當我點擊創建其他出價查詢按鈕時,表單不會隱藏自己。當我使用$ scope函數替換變量時,例如$ scope.index = 0;該程序起作用。
我不認爲問題在於使用this.index,因爲它適用於我的其他程序。那麼,確切的問題是什麼?
我想你不能在同一個控制器中使用這個和$ scope – edi9999
這是一個錯字。我剛剛更新了我的問題。 –
爲什麼你要使用'this'而不是'$ scope'? –