Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I recently started to digg in to angularjs, and would help me a lot with my new project, but im stucked with the view structure part.

So what i dont really understand is, how to build it up. Is it okay if i create html angular partials and not creating laravel views, so laravel would only handle the database instert fecth edit delete, and the angular partial views would handle the result show, and forms.

So my buold up would look like this. My assets folder

/css
/img
/js
 /lib
 /partials
         /home
             index.html
         /users
             users.html
             details.html

And creating restful controllers for them what handlets listed above

Or if someone could show my a basic exaple about this, just the controller and view part, how to build up a singple page with showing result, and one with grabing by id i would really be grateful.

Thank you

share|improve this question

2 Answers

up vote 6 down vote accepted

Like most of the JS frameworks, they usually get data via ajax, so you could just make your routes restful, and get the data via ajax, i dont see why you should have to make static html files inside your public folder.

For example: (Laravel 4)

Route::get('/api', function()
{
    return YourModel::all();
});

This will return JSON as default, and the JSON can be used by Javascript, so this means you could just build your server side code as an API, and do the rest with Angular.

The same example with the Javascript:

$.getJSON('api', function(data) {
    $scope.$apply(function(){
        $scope.YOURSCOPE = data;
    });
});

Here you bind the data to your scope.

Finally just use the data as you see fit.

Same example, but this time the View: (Normal Laravel view)

{{YOURSCOPE.JSONobject }}

So if your api returns:

[{"id":1,"info":"This is some random content","created_at":"2013-01-24 16:48:41","updated_at":"2013-01-24 16:48:41"}

You can bind it to your Angular/Laravel Views like this:

{{YOURSCOPE.id }}
{{YOURSCOPE.info }}
{{YOURSCOPE.created_at }}
{{YOURSCOPE.updated_at }}

Just remember to not confuse the blade template engine to render the curlybrace syntax. You can however change the Angular or Laravel template syntax in the settings, so they dont confuse each other.

Hope this helps!

share|improve this answer
thank you for the clear explanation sir – Side Jan 31 at 9:18

This is one of the project I am working on. You can see the way how I have partial views in angular js. As suggested above, there is no need putting your view files in public folder.

https://github.com/naveensky/wm-demo-tracker

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.