javascript - adding data to json-ld using angualrjs -
i'm beginner in angularjs , i'm stuck in 1 of projects. want data user enters in form converted format:<<"schema:data">> , pushed , displayed inside @graph of json-ld. html , 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> json </h1> <p> {{output}} </p> </div> </body> </html>
$scope.output['@graph'].push({ "@id": "person", "@type": "schema:person", });
Comments
Post a Comment