eternalStud
eternalStud

Reputation: 83

View json and click links.json inside that json and replace it with the current json view

What Im saying is, lets say I load a json and view it in HTML. This json contains URL to other json's. Is there a way to click those links(to new json's) and have it replace with the current view?

e.g

{
"something":[
{
"href":newJSON link/" },

so when i in HTML click that link it should open the contents of the refereed json and view its content instead of the content from the previous json.

Hope it was an understandable question.

Thanks in advance.

Upvotes: 0

Views: 53

Answers (1)

Second2None
Second2None

Reputation: 472

If your json is valid json like

"json_variable" : {
      "key": "value",
      "href": "valid_url_to_other.json"
 }

and this json is bound to $scope.myJson you could render it like

<button ng-repeat="json in myJson" ng-click="loadJson(json.href)">{{json.key}}</button>

finally you have to define the loadJson() function in your controller:

$scope.loadJson = function(jsonUrl) {
    // implement here the retrieving of your new json from 'jsonUrl'
    $scope.myJson = yourNewJsonData;
}

Upvotes: 1

Related Questions