Angular js project not working

I am working on a small project with angular js (ps: this is the first time i use it) and i am blocked by this error and i dont understand why

angular.module("jsonerator", [])
.controller('theController', function ($scope) {

    $scope.personld = {
        "@context": {
            "schema": "http://schema.org/"
        },
        "@graph": [
            {
                "@id": "person",
                "@type": "schema:Person",
            }
        ]
    }

    $scope.personld["@graph"][0]["schema:givenName"] = "";
    $scope.personld["@graph"][1]["schema:familyName"] = "";
}

      

+3


source to share


2 answers


To fix the error, you need to add another object to your @graph array and it should work. Then it will be determined ["@graph"][1]

. The problem was that you only had one element in your array.



"@graph": [ 
   { "@id": "person", "@type": "schema:Person" }, 
   {} 
]

      

+2


source


Your array @graph

is only 1 element long, so it $scope.personld["@graph"][1]

doesn't exist and the command $scope.personld["@graph"][1]["schema:familyName"] = "";

throws an error.



+1


source







All Articles