0
AngularJSテンプレート内でパラメータを動的に機能させる方法を知りたい。 テーブルに多数の行があり、各行にボタンがありますを追加します。このボタンのng-click機能に行番号を渡したいと思います。AngularJSテンプレート内で機能するためにパラメータを渡す
ここは私のテンプレートの抜粋です:
<div id="documentsTable" class="table-responsive">
<table class="table">
<thead>
...
</thead>
<tbody ng-repeat="document in data">
<tr>
...
<td>
...
<button ng-show="document.depositCheckbox" ng-click="addDeposit({id: document.number})" id="addDepositBtn"
type="submit" class="btn btn-primary">Add deposit</button>
</td>
</tr>
</tbody>
</table>
指令:
.directive('documentDirective', ['$compile', '$templateCache', function() {
return {
templateUrl: 'templates/documentTemplate.html',
scope: {
data: '=',
addDeposit: '&'
},
restrict: 'E'
}}]);
そして、私が持っている私のHTMLファイル内:
<document-directive data="documents" add-deposit="addDeposit()"></document-directive>
機能addDeposit私の中コントローラ:
$scope.addDeposit = function(documentId) {
for(var i=0; i<$scope.documents.length; i++) {
if($scope.documents[i].number == documentId) {
var depositLength = $scope.documents[i].deposit.length;
var deposit = {'number': depositLength, 'value': 0, 'paymentDate': new Date(), 'firstRow': false};
$scope.documents[i].deposit.push(deposit);
break;
}
}
}
ありがとう!
my ** id:document.number **はrowNumberを格納するため、問題は解決しません。問題は、私のaddDeposit関数でこの値を取得できないということです。これは未定義です。 – piotrb
それは次のようになります: 私のHTML要素で宣言した関数addDeposit()にはパラメータがありません。したがって、テンプレート内でこの関数にパラメータを渡すことはできません。 – piotrb
変数を宣言する必要がないので、何もする必要はありません。あなたは 'addDeposit'関数を定義するコントローラコードをいくつか投稿できますか? –