Spdexter
Spdexter

Reputation: 933

angular JS access attribute from an array of objects

$completed = [Object { count(1)="7", gid="306"}, Object { count(1)="1", gid="311"}]

How do I get count(1) = 7 in an HTML template?

<div class="{{ completed | filter : group.gid }}">

so

{{ completed | filter : group.gid }}  

evaluates to

[{ "count(1)":"7","gid":"306"}]

I just need '7'?

Upvotes: 2

Views: 92

Answers (1)

Shashank Agrawal
Shashank Agrawal

Reputation: 25797

Here you go:

<div class="{{(completed | filter: group.gid)[0]["count(1)"]}}" >

See the working demo:

var app = angular.module("sa", []);

app.controller("FooController", function($scope) {

  $scope.group = {
    gid: 7
  };

  $scope.completed = [{
    "count(1)": "7",
    gid: "306"
  }, {
    "count(1)": "1",
    gid: "311"
  }]
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<div ng-app="sa" ng-controller="FooController">
    {{(completed | filter: group.gid)[0]["count(1)"]}}
</div>

Upvotes: 1

Related Questions