1

I am trying to style the JSON message to the required style.

the required style of JSON message looks like:

[   
{
“question”: “Write down Nhat’s email”,
    “answer”: “[email protected]”,
    “inline”: true
},
{
<% NEXT QUESTION/ANSWER %>
},
{
<%…%>
}
]

and currently my JSON message looks like:

[{"Question":"Question","Note":"","notePlaceholder":"enter text","inlineChecked":false},{"Question":"Question","Note":"","notePlaceholder":"enter text...","inlineChecked":""}]

Any idea on that?

This is the link of my code

2
  • 1
    Are you trying to add line breaks into a JSON display in a UI? Commented Feb 28, 2014 at 19:33
  • @Reboog711 yes,correct Commented Feb 28, 2014 at 19:38

1 Answer 1

1

You could use the json filter on the object in a pre tag.

 <pre>{{json | json}}</pre>

Plunk

Regarding your question, you could add a $watchCollection on json, and in the handler iterate through the items and delete the property you don't want.

   $scope.$watchCollection('json', function(values) {
      angular.forEach(values, function(item) {
        delete item.notePlaceholder;
      });
    });

Note, you're simply passing a reference from $scope.items to $scope.json, so if you modify one it will modify the other. If you don't want that, use angular.copy to make a separate copy. I've also update the plunk.

Sign up to request clarification or add additional context in comments.

2 Comments

btw, how should i remove one item, like "notePlacehoder" in the json message?
you could add a watch on that item, so when it changes you could call delete $scope.json.notePlaceholder; or something like that

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.