1

I'm a beginner in AngularJS and I'm stuck in one of my projects. I want the data that the user enters in the form to be converted to the format:<<"schema:data">> and be pushed and displayed inside the @graph of the json-ld. this my html and angular codes:

angular.module("watch", [])

.controller("ctrl", function($scope) {
    $scope.output = {
            "@context": {
            "schema": "http://schema.org/"
   },
           "@graph": [{
            "@id": "person",
   "@type": "schema:Person",
   }
   ]
 
    }


    $scope.volatile = {};
    $scope.output["@graph"][0]["schema:givenName"] = "";
 
 
    $scope.$watch(function(scope) {
            return scope.volatile
 
        },
  function(newValue, oldValue) {
          $scope.output = newValue;
       
   
  
        });
  
})
</script>
head>
    <title>
      reelyActive: Angular Test 
    </title>
 
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.13/angular.min.js">
    </script>
    <script type="text/javascript" src="watch.js">
    </script>
 <link rel="stylesheet" href="style.css" />
  </head>
  <body ng-app="watch">
  <ul>
<li><a href="product.html">Product</a></li>
<li><a href="place.html">Place</a></li>

</ul><br/><br/>
    <div ng-controller="ctrl">
      <form>
        GivenName:  
        <input type="text" ng-model="volatile.givenName">
        <br/>
        FamilyName: 
        <input type="text" ng-model="volatile.familyName">
        <br/>
        Gender: 
        <input type="text" ng-model="volatile.gender">
        <br/>
        Nationality:
        <input type="text" ng-model="volatile.nationality">
        <br/>
        WorksFor: 
        <input type="text" ng-model="volatile.worksFor">
        <br/>
        JobTitle:
        <input type="text" ng-model="volatile.jobTitle">
        <br/>
        Url: 
        <input type="text" ng-model="volatile.url">
        <br/>
        Image:
        <input type="text" ng-model="volatile.image">
        <br/>
         </form>
         <h1>
           Your JSON
         </h1>
         <p>
           {{output}} 
         </p>
    </div>
 
 
 
 
  </body>
</html>
JSON C11
  • 11,272
  • 7
  • 78
  • 65
reus
  • 51
  • 1
  • Possible duplicate of [appending data to json-ld using angularjs](https://stackoverflow.com/questions/30180486/appending-data-to-json-ld-using-angularjs) – Anthropic Aug 23 '17 at 03:41

1 Answers1

0
$scope.output['@graph'].push({
        "@id": "person",
        "@type": "schema:Person",
        });
Hardy
  • 542
  • 4
  • 10