I am new to angularjs and trying create an single page application. I have a home controller with very simple code. Something along the lines of this tutorial
Angular JS controller is initialized with code like:
var phonecatApp = angular.module('phonecatApp', []);
phonecatApp.controller('PhoneListCtrl', function ($scope) {
$scope.phones = [
{'name': 'Nexus S',
'_id': 1,
'snippet': 'Fast just got faster with Nexus S.'},
{'name': 'Motorola XOOM™ with Wi-Fi',
'_id': 2,
'snippet': 'The Next, Next Generation tablet.'},
{'name': 'MOTOROLA XOOM™',
'_id': 3,
'snippet': 'The Next, Next Generation tablet.'}
];
});
but in production data might not be so neatly packed. Now my problem is:
Can I create a download link to a JSON representation of my objects?
<li ng-repeat="phone in phones">
<a
href="data:text/json;charset=utf-8,{{encodeURIComponent(JSON.stringify(phone))}}"
download="{{phone._id}}.json">
JSON
</a>
</li>
I basically want to access the current object phone
with the formatting function encodeURIComponent(JSON.stringify(phone))
.
Is there a way to do this neatly?