0

I am trying to display only the names of my array elements with angular but it is not working, can you please help? here is the code:

<div ng-app="myapp" ng-controller="MyController" ng-model="myData">
    <ul>
        <li ng-repeat="item in myData.items"
               ng-click="myData.doClick(item, $event)">{{myData.item.name}}</li>
    </ul>
</div>

<script>
    angular.module("myapp", [])
            .controller("MyController", function($scope) {
                $scope.myData = {};
                $scope.myData.items = [{ name: "1"}, { name: "2"}, { name : "3"} ];

                $scope.myData.doClick = function(item, event) {
                    alert("clicked: " + item.name + " @ " + event.clientX + ": " + event.clientY);
                }


            } );
</script>  

1
  • {{myData.item.name}} instead of this you have to write this {{item.name}} Commented May 21, 2015 at 5:30

1 Answer 1

3

You just have to write in the expression as below
{{item.name}}

Sign up to request clarification or add additional context in comments.

Comments

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.