Ken Ken - 2 years ago 237
AngularJS Question

Loading partial html template into Angular app using Laravel

I'm trying to use the RouteProvider functionality in Angular. A different partial html template should be loaded depending on whether the user is editing a form, viewing a list of completed entries, etc. I've been unable to load the html templates within the same page. Instead, the user is redirected to a different page.

Here's the relevant Angular code:

.when(/new', {
controller: 'CreateCtrl'
templateUrl: 'partials/newform.html'

The Laravel Route:

Route::resource('services', 'ServicesController');

The newform.html file is located at resources/views/partials/newform.html within Laravel.

Any thoughts on how I can load these partial html templates from Laravel?

Answer Source

One way would be to reference the full path to the partials

.when('/new', {
   controller: 'CreateCtrl'
   //depending on your path adjust it
   templateUrl: 'partials/newform'

since you are just using .html not tempalte.blade.php file for template you should move it to public folder.

Update: If you really dont want to move the template out of view folder of laravel

create a route and serve your html from there

Route::group(array('prefix' => 'partials'), function(){

      Route::get('/newform', function()
        return File::get(app_path().'Views/partials/angular.html');

Note: I will suggest you not to mix Laravelc template with Angular, keep Laravel as REST API, and your Angular should separate layer.

Here are some Pros and Cons for both approach

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download