Search code examples
laravel-5angular-directive

AngularJs directive templateURL in Laravel5.2


I want to use angular directive in my laravel project. But when I try to call my angular directive, tempateUrl of Angular Directive is not found. My Code is given below:

html

 <demographich-url></demographich-url>

JS

 .directive('demographichUrl', [function () {
        return {
            restrict: 'EA',
            replace: true,
            templateUrl: 'demographich', // this doesn't work
            // 'templateUrl: './views/comments/comment-form.html', // this doesn't work
           // 'templateUrl: './views/comments/comment-form.blade.php', // this doesn't work
            // template:'<h1> hello world! </h1>',  // this works
        };
    }])

Laravel Routes

   // routes
  Route::get('demographich', 'CompanyController@demographich');


   // controller
    public function demographich()
   {
       return view('comments.comment-form');
   }

** comment-form.blade.php ( templateUrl page [ this page not found ] )**

    <h1> Hi your comments goes here!!!!  </h1>

** My file structure **

 |
 | ---  resources
        | --- views
              | -- comments
                    | -- comment-form.blade.php

NB: Laravel : 5.2 Angular: 1.5.X


Solution

  • I have solved this problem using below directive code.

    .directive('demographichUrl', function () {
        return {
            restrict: 'EA',
            scope: {
                obj: '=',
                submitFunc: '&'
            },
            templateUrl:  '<?= asset('app/directive/demograph/demographich.html') ?>',
            link: function (scope, iElement, iAttrs) {
    
            }
        };
    })