0

I am using the angular ng-repeat function, in my controller i am trying to create an array however i keep getting an error message in my inspector.

Uncaught SyntaxError: Unexpected token [ 

below is a snippet of my code..

var app = angular.module("homeApp", []);
 app.controller("entriesView", function ($scope){
$scope.itemEntry = {[
    {

    image: "https://cms.myspacecdn.com/cms/x/13/47/112013-priscilla-600.jpg"
    },
    image1: "https://cms.myspacecdn.com/cms/x/13/47/112013-priscilla-600.jpg"


];
  }

});

can someone let me know where i am going wrong, thanks

2 Answers 2

2

Recreate itemEntry like:

$scope.itemEntry = [            
    {image: "https://cms.myspacecdn.com/cms/x/13/47/112013-priscilla-600.jpg"},
    {image1: "https://cms.myspacecdn.com/cms/x/13/47/112013-priscilla-600.jpg"}    
];

The itemEntry represents list of objects but not Object of list

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

Comments

1

Array uses [] braces. You wrapped your array in {} which is for objects. Objects need key/value pairs, so since your object only contains the array is throwing a syntax error

Remove outer {}

2 Comments

yeah, you are right. deleted my answer. I did not want to be rude or anything, just think that you really need have some solid foundations in JS before learning AngularJS.
@arturgrzesiak agree that more than basic knowledge of objects/arrays is needed...especially to understand scope...just better to be diplomatic. No need to delete answer

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.