Lukas Tilch Lukas Tilch -3 years ago 85
AngularJS Question

shorten ng-repeat variable with limitTo

In my DB I have Datastructure like this

"Year2016":[{"Name": "Project1"},{"Name": "Project2"}],
"Year2017":[{"Name": "Project1"},{"Name": "Project2"}]

i go

ng-repeat="year in Projects"
<b>{{year | limitTo:4:6}}</b>

instead of
i get the whole

if i put the query response in the code as a string it works as suspected but

for some reason the
is not working on the new

Is it possible at all?

Answer Source

you should use a (key, value) syntax ng-repeat to loop through json object array with the keys.

refer the below example:

angular.module("app", [])
  .controller("myCtrl", function($scope) {
    $ = {
      "Projects": [{
        "Year2016": [{
          "Name": "Project1"
        }, {
          "Name": "Project2"
        "Year2017": [{
          "Name": "Project1"
        }, {
          "Name": "Project2"
<script src=""></script>
<div ng-app="app" ng-controller="myCtrl">
  <div ng-repeat="project in data.Projects">
    <div ng-repeat="(key, value) in project">
      <b>{{key | limitTo:4:4}}</b>
      <div ng-repeat="item in value">

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download