teddy2sticks teddy2sticks - 1 year ago 75
AngularJS Question

How to use ng-click value as ng-repeat property?

How to get


Button click calls a function, passing in two parameters:

<a ng-click="display('Info', 'Admission_Info'); filters.Admission_Info= '!!'; ">Info</a>
<a ng-click="display('Info', 'SomeOther_Info'); filters.SomeOther_Info= '!!'; ">Other</a>

Function in the controller:

$scope.display = function (col, val) {
$scope.filters = {};
$scope.clickedColumn = col;
$scope.clickedVal = val;

Table displays a filtered view with 2 columns.

<tr ng-repeat="r in response | filter:filters as filtered " ng-show="filtered.length">
<td>{{ r.Name }}</td>
<td>{{ r.clickedVal }}</td>

{{ r.{{clickedVal}} }}
didn't work.

So for example, if the first button is clicked,
should return

I've tried creating a filter as well but run into the same issue -
is incorrect.

SchoolProgramsApp.filter('myFilter', function () {
return function (input, column, value) {
var out = [];
angular.forEach(input, function (m) {
if (m.value === value) {
return out;

Answer Source

You should use bracket notation to access property of the object by variable name:

{{ r[clickedVal] }}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download