Laravel5.2中的AngularJs指令templateURL

时间:2016-05-18 09:52:19

标签: laravel-5.2 angular-directive

我想在 laravel项目中使用angular指令。但是当我尝试调用我的角度指令时,找不到 Angular Directive的tempateUrl 。我的代码如下:

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 [此页面未找到])**

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

**我的文件结构**

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

NB: Laravel: 5.2 Angular: 1.5.X

2 个答案:

答案 0 :(得分:3)

我使用下面的指令代码解决了这个问题。

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

        }
    };
})

答案 1 :(得分:0)

您可以在指令中使用laravel blade页面。

.directive('surveyHeader', function () {
    return {
        restrict: 'EA',
        scope: {
            obj: '=',
            submitSurveyheader: '&'
        },
        templateUrl:  '<?php echo asset('app/directive/surveyheader/surveyheader.blade.php') ?>',

        link: function (scope, iElement, iAttrs) {

        }
    };
})