0

I use a snippet which loads strings from an external json-file. Everything works fine, but when I start the function locally, I get a 'cross origin'-issue. Therefore, I want to put the strings directly in my JS, but it do not work.

Origin JS

$scope.loadAutosuggest = function(query) {
    return $http.get('data.json');
};

data.json

[
    "In Progress: Yes",
    "In Progress: No"
]

I´ve tried to do this like here (but it do not work)

$scope.loadAutosuggest = [
 "In Progress: Yes",
 "In Progress: No"          
];

Do you have any tips for me? Thank you

13
  • are you just running the function locally as in just run the .html file that you have got? Commented Jun 21, 2015 at 12:42
  • Try start server on localhost. You can use grunt github.com/gruntjs/grunt-contrib-connect SimpleHTTPServer docs.python.org/2/library/simplehttpserver.html or any you have in touch Commented Jun 21, 2015 at 12:43
  • 1
    You missed an equals sign before your array. Also make sure that $scope is already defined Commented Jun 21, 2015 at 12:44
  • 1
    Which server are u using? Are you at least running the app on a server when u say 'running it locally'? You are doing a $http.get() obviously needs resources on server.. Commented Jun 21, 2015 at 12:48
  • 1
    hey, can you show the code on your html page? I hope you are not trying to pass any parameter from the page to loadAutoSuggest function, coz u dont need to... it should be just ng-repeat="autoSuggest in loadAutoSuggest" not ng-repeat="autoSuggest in loadAutoSuggest(someParam) Commented Jun 21, 2015 at 12:59

1 Answer 1

2

The problem is probably that $scope.loadAutosuggest is expected to be a function.

$scope.loadAutosuggest = function() {
  return [
    "In Progress: Yes",
    "In Progress: No"          
  ];
};
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.