I'm very new to AngularJS, and have tried to find an answer to my following question around the web.
So my issue is as follows: I have a handler (.ashx) file on my site. The handler returns a JSON array. It's located on the following URL: /services/returnsites.ashx
It's a quite simple JSON aray that looks like this:
[{"NodeId":a93064,"NodeName":"Planes"},{"NodeId":a49856,"NodeName":"Bicycles"},{"NodeId":a19631,"NodeName":"Cars"}]
I'd like to loop through each of the sites in the json array.
I have an html-file containing this:
<div ng-controller="My.Controller">
<ul>
<li ng-repeat="site in sites">
{{site.NodeName}} - {{site.NodeId}}
</li>
</ul>
</div>
I have a controller as well, looks like this:
angular.module("umbraco").controller("My.Controller", function($scope) {
...
});
What I need is to put something instead of the trhee dots to grab the array from the json file.
I can get it working if I my controller looks like this (containing the array the controller file):
angular.module("umbraco").controller("My.Controller", function($scope) {
$scope.sites = [
{
NodeName: "Planes",
NodeId: "a93064"
},
{
NodeName: "Bicycles",
NodeId: "a49856"
},
{
NodeName: "Cars",
NodeId: "a19631"
}
];
});
But I can't get it working if I'm trying to grab the array from the file on the server. I've tried a couple of different things including something like the $hhtp.get() etc. copied from around the web, but nothing seems to work :(
I hope that someone can help me out.
Thank you very much in advance.
/Kim
$httpcertainly seems to be one way to do it in this case, so possibly it's a CORS issue.. Do you see any errors in the JS console if you use a simple$http.get()call?