Skip to content Skip to sidebar Skip to footer

Appending Data To Json-ld Using Angularjs

I am newbie in angularjs and I started on the project to learn more about this framework. I make an application that puts data in a json-ld.my app can add data to the json-ld but w

Solution 1:

I think this is what you are looking for. Fiddle

What I changed in your code :

  1. I use ng-change instead of $watch. Different between them : Reference

  2. I create a changeKeyValue method to extract key value from $scope.volatile and append it to your @graph when any changes happen to input

    for (var key in $scope.volatile) {
    
        if ($scope.volatile.hasOwnProperty(key)) {
            $scope.output["@graph"][0]["schema:" + key] = $scope.volatile[key];
        }
    }
    

    Basically it just loop through the object, extract key-value and append it to your output. Hope it helps.

Post a Comment for "Appending Data To Json-ld Using Angularjs"