1

JSbin for live code example

Is it possible to display only the key from expression syntax in Angular? The key being the word being "page". If so can it be from an array(I know they are the same word)?

HTML

<body ng-app="ang6App">
    <div class="container" ng-controller="templatesCtrl">
        <div ng-repeat="(key, val) in tempTemp">{{val}}</div>
        <!-- how do I just display the word page? -->
    </div>
</body>

JS

angular.module("ang6App")
    .controller("MainCtrl", function ($scope) {})
    .controller("templatesCtrl", function ($scope) {
    /* $scope.template = Templates; */
    $scope.tempTemp = [{
        'page': {
            'name': 'jordan test page'
        }
    },
    //end of page
    {
        'page': {
            'name': 'jordan test page'
        }
    }];
    //end of templates
});

1 Answer 1

5

The first repeater is just an array so it has no key/value pair

the second repeater loops through all property in item

<div ng-repeat="item in tempTemp">
  <div ng-repeat="(key, val) in item">
    {{key}}
  </div>
</div>
Sign up to request clarification or add additional context in comments.

2 Comments

Will mark this correct but is there anyway in angular to call the key directly? {{tempTemp[1].key}} without repeating?
then you would have to do something like $scope.getKeys = function(obj){ return Object.keys(obj) } and {{getKeys(item)}}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.