I have a factory which loads datas from array, or a selected element from this array. But if I move it to an external .json file, I just get errors - i am newbie to angular in all but trying hard, keep in mind ^^ So if I use the simple
$http.get('ports.json').success (function(data){
var works = data;
});
code, I get "ReferenceError: works is not defined". And if I try the
$http.get('ports.json').then((portRes){
var works = res.data;
});
I get the "Uncaught SyntaxError: Unexpected token {" error. But that code in not a factory, on a whole different page works, so no idea what can be wrong now :/ Here is the .json filet, and @ the link, you can check the plunker. Plunker - http://plnkr.co/edit/tMrJMjzc4pl7fQ1PIEiO?p=info
[
{
"Title": "Sprite",
"subTitle": "",
"Link": "sprite",
"Thumbnail": "img/portfolio02.png",
"Image": "img/ismont.png"
},
{
"Title": "Pepsi",
"subTitle": "Kristályvíz",
"Link": "pepsi",
"Thumbnail": "img/portfolio03.png",
"Image": "img/sanofimont.png"
}
]
EDIT: So I tried all what u wrote till now but nothing seemd to work... So I have thiw well-working factor now, which I want to transfer to an external .json file, to be very very clear for understand.
portApp.factory("workFactory", function($http) {
var works = [
{
Title: "Sprite",
subTitle: "",
Link: "sprite",
Thumbnail: "img/portfolio02.png",
Image: "img/ismont.png"
},
{
Title: "Pepsi",
subTitle: "Kristályvíz",
Link: "pepsi",
Thumbnail: "img/portfolio03.png",
Image: "img/sanofimont.png"
}
];
return {
list: function() {
return works;
},
selected: function(detPath) {
selected = works.filter(function(work) {
return work.Link == detPath;
});
return selected;
}
};