WebサービスからJSONで作成したテーブルを表示しようとしていて、配列を作成しています。配列の長さは0です。ボタンをクリックすると、配列に1要素を追加してテーブルに新しい行を追加します。ボタンをクリックしても、配列の要素が追加されず、その理由がわかりません。同じコントローラとビューで2つの異なるng-repeatを持つことは可能ですか?単一のビューで複数のng-repeatを使用する
コントローラがあります:
assets.controller('EditaTipusCtrl', function ($scope, $http, $routeParams) {
$http.get('http://10.0.203.73/WS/ws.php/tipusactius/getDetails/' + $routeParams.id).success(function (data) {
$scope.atrb = data;
});
$scope.nousAtributs = [];
$scope.addNewLine = function() {
var newRow = {
"nomAtribut": "",
"tipus": "",
"mida": '',
"prioritat": "",
"obligatori": "",
"observacions": "",
"nomTipusActiu": $routeParams.id // nom del tipus d'actiu
};
$scope.nousAtributs.push(newRow);
// return $scope.nousAtributs;
}
});
とビュー:
解決<div class="col-md-10">
<div ng-controller="EditaTipusCtrl" id="test">
<div class="row">
<button class="btn btn-default" >
<span class="glyphicon glyphicon-plus" aria-hidden="true" ng-click="addNewLine()"></span>
Afegir atribut
</button>
</div>
<br />
<table class="table">
<tr>
<th>#</th>
<th><a href="" ng-click="sortField = 'ordre'; reverse = !reverse">Prioritat</a></th>
<th><a href="" ng-click="sortField = 'nomAtribut'; reverse = !reverse">Atribut</a></th>
<th><a href="" ng-click="sortField = 'midaAtribut'; reverse = !reverse">Mida</a></th>
<th><a href="" ng-click="sortField = 'atributObligatori'; reverse = !reverse">Obligatori</a></th>
<th><a href="" ng-click="sortField = 'observacions'; reverse = !reverse">Observacions</a></th>
</tr>
<tr ng-repeat="(key, value) in atrb">
<td></td>
<td>
<input type="number" ng-model="value.ordre" value="value.ordre" />
</td>
<td>
<input type="value.valor" ng-model="value.nomAtribut" value="value.nomAtribut" />
</td>
<td>
<input type="value.valor" ng-model="value.midaAtribut" value="value.midaAtribut" />
</td>
<td>
<input type="checkbox" ng-model="value.atributObligatori" value="value.atributObligatori" ng-true-value="'Si'" ng-false-value="'No'" />
</td>
<td>
<input type="value.valor" ng-model="value.observacions" value="value.observacions" />
</td>
</tr>
<tr ng-repeat="a in nousAtributs">
<td></td>
<td>
<input type="number" ng-model="a.ordre" value="a.ordre" />
</td>
<td>
<input type="a.valor" ng-model="a.nomAtribut" value="a.nomAtribut" />
</td>
<td>
<input type="a.valor" ng-model="a.midaAtribut" value="a.midaAtribut" />
</td>
<td>
<input type="checkbox" ng-model="a.atributObligatori" value="a.atributObligatori" ng-true-value="'Si'" ng-false-value="'No'" />
</td>
<td>
<input type="a.valor" ng-model="a.observacions" value="a.observacions" />
</td>
</tr>
</table>
<button class="btn btn-default" >
<span class="glyphicon glyphicon-floppy-disk" aria-hidden="true"></span>
Guardar
</button>
</div>
</div>
:
私はspanタグ
代わりにボタンのタグにNGクリックを置きますよろしくお願いいたします。
コンソールでエラーを得ていますか? 'newRow'で設定しているプロパティは、テーブルに出力しようとしているプロパティと一致していないようです。たとえば、最初のカラムには 'ng-model =" a.ordre "'がありますが、作成している 'newRow'オブジェクトには" ordre "プロパティはありません。 – Lex
スパンタグの代わりにボタンタグにng-clickを入れました。とにかくありがとう – proktovief