1

I have an app that's completely a 'round trip' app, as AngularJS would put it. I'm setting up a sidebar to use AngularJS but I'm a bit confused about next steps. Have the following example placed on my page just as a starting point (one of their homepage examples, no big win here):

http://jsfiddle.net/w5LKa/

What I'd like to do is figure out how to get data from my database rather than hard coding this:

$scope.todos = [{
    text: 'learn angular',
    done: true },{
    text: 'build an angular app',
    done: false
}];

I'm happy to set up a table with just these two field for purposes of essentially completing this tutorial. From what I've read, a good way to go seems to be configuring an API, but that isn't something I really want to dive into right now. I just have normal models that return arrays, as specified by a single query.

Can anyone shed some light about how I can do this? I'm working in Codeigniter as my server side framework.

Thanks!

1 Answer 1

2

You can get your data with $http

For example:

$http({
   url: "some url here",
   method: "POST",
   data: {"key":"value"}
}).success(function(data, status, headers, config) {
    $scope.data = data;
}).error(function(data, status, headers, config) {
    $scope.status = status;
});

Or you can use $resource, the documentation is here

Sign up to request clarification or add additional context in comments.

2 Comments

So would that 'some url here' just be a controller that returns model data as json? Is that a fair way to set it up server side?
Yes, the url can point to a controller's action that returns json. That's the way i use it. :) If you only want the json data you can use the method: "GET" instead of "POST".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.