Note that there are some explanatory texts on larger screens.

plurals
  1. POAngularJS: factory $http.get JSON file
    text
    copied!<p>I am looking to develop locally with just a hardcoded JSON file. My JSON file is as follows (valid when put into JSON validator):</p> <pre><code>{ "contentItem": [ { "contentID" : "1", "contentVideo" : "file.mov", "contentThumbnail" : "url.jpg", "contentRating" : "5", "contentTitle" : "Guitar Lessons", "username" : "Username", "realname" : "Real name", "contentTags" : [ { "tag" : "Guitar"}, { "tag" : "Intermediate"}, { "tag" : "Chords"} ], "contentAbout" : "Learn how to play guitar!", "contentTime" : [ { "" : "", "" : "", "" : "", "" : ""}, { "" : "", "" : "", "" : "", "" : ""} ], "series" :[ { "seriesVideo" : "file.mov", "seriesThumbnail" : "url.jpg", "seriesTime" : "time", "seriesNumber" : "1", "seriesTitle" : "How to Play Guitar" }, { "videoFile" : "file.mov", "seriesThumbnail" : "url.jpg", "seriesTime" : "time", "seriesNumber" : "2", "seriesTitle" : "How to Play Guitar" } ] },{ "contentID" : "2", "contentVideo" : "file.mov", "contentThumbnail" : "url.jpg", "contentRating" : "5", "contentTitle" : "Guitar Lessons", "username" : "Username", "realname" : "Real name", "contentTags" : [ { "tag" : "Guitar"}, { "tag" : "Intermediate"}, { "tag" : "Chords"} ], "contentAbout" : "Learn how to play guitar!", "contentTime" : [ { "" : "", "" : "", "" : "", "" : ""}, { "" : "", "" : "", "" : "", "" : ""} ], "series" :[ { "seriesVideo" : "file.mov", "seriesThumbnail" : "url.jpg", "seriesTime" : "time", "seriesNumber" : "1", "seriesTitle" : "How to Play Guitar" }, { "videoFile" : "file.mov", "seriesThumbnail" : "url.jpg", "seriesTime" : "time", "seriesNumber" : "2", "seriesTitle" : "How to Play Guitar" } ] } ] } </code></pre> <p>I've gotten my controller, factory, and html working when the JSON was hardcoded inside the factory. However, now that I've replaced the JSON with the $http.get code, it doesn't work. I've seen so many different examples of both $http and $resource but not sure where to go. I'm looking for the simplest solution. I'm just trying to pull data for ng-repeat and similar directives.</p> <p>Factory:</p> <pre><code>theApp.factory('mainInfoFactory', function($http) { var mainInfo = $http.get('content.json').success(function(response) { return response.data; }); var factory = {}; // define factory object factory.getMainInfo = function() { // define method on factory object return mainInfo; // returning data that was pulled in $http call }; return factory; // returning factory to make it ready to be pulled by the controller }); </code></pre> <p>Any and all help is appreciated. Thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload