UI Bootstrap和Laravel Blade模板

时间:2014-10-01 12:37:39

标签: laravel-4 angular-ui-bootstrap

我在我的项目中使用UI Bootstrap:UI Bootstrap

问题:我无法使用刀片模板处理javascript <script>标记。获取内部服务器错误(500)

这是观点路径:

视图

  • 包括
  • 布局

我的包含/ head.blade.php 文件:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="">
<meta name="author" content="Scotch">

<title>Title</title>

{{ HTML::style('../public/css/bootstrap.min.css') }}
{{ HTML::script('//public/js/jquery-1.11.1.js')}}

这是 layouts / home.blade.php 文件:

<!doctype html>
<html ng-app="ui.bootstrap.demo">
<head>
    @include('includes.head')
    {{ HTML::script('//public/js/ui.bootstrap.min.js') }}
    {{ HTML::script('//public/js/angular.min.js')}}
    {{ HTML::script('//public/js/example.js')}}
</head>
<body>
<div class="container">

    <header class="row">
        @include('includes.header')
    </header>

    <div id="main" class="row">
        @yield('content')
    </div>

    <footer class="row">
        @include('includes.footer')
    </footer>

</div>
</body>
</html>

这是我的 pages / home.blade.php 文件:

@extends('layouts.home')
@section('content')
    <div ng-controller="ModalDemoCtrl">
        <script type="text/ng-template" id="myModalContent.html">
            <div class="modal-header">
                <h3 class="modal-title">I'm a modal!</h3>
            </div>
            <div class="modal-body">
                <ul>
                    <li ng-repeat="item in items">
                        <a ng-click="selected.item = item">{{ item }}</a>
                    </li>
                </ul>
                Selected: <b>{{ selected.item }}</b>
            </div>
            <div class="modal-footer">
                <button class="btn btn-primary" ng-click="ok()">OK</button>
                <button class="btn btn-warning" ng-click="cancel()">Cancel</button>
            </div>
        </script>

        <button class="btn btn-default" ng-click="open()">Open me!</button>
        <button class="btn btn-default" ng-click="open('lg')">Large modal</button>
        <button class="btn btn-default" ng-click="open('sm')">Small modal</button>
        <div ng-show="selected">Selection from a modal: {{ selected }}</div>
    </div>
@stop

这是 public / js / example.js 文件:

angular.module('ui.bootstrap.demo', ['ui.bootstrap']);
angular.module('ui.bootstrap.demo').controller('ModalDemoCtrl', function ($scope, $modal, $log) {

  $scope.items = ['item1', 'item2', 'item3'];

  $scope.open = function (size) {

    var modalInstance = $modal.open({
      templateUrl: 'myModalContent.html',
      controller: 'ModalInstanceCtrl',
      size: size,
      resolve: {
        items: function () {
          return $scope.items;
        }
      }
    });

    modalInstance.result.then(function (selectedItem) {
      $scope.selected = selectedItem;
    }, function () {
      $log.info('Modal dismissed at: ' + new Date());
    });
  };
});

// Please note that $modalInstance represents a modal window (instance) dependency.
// It is not the same as the $modal service used above.

angular.module('ui.bootstrap.demo').controller('ModalInstanceCtrl', function ($scope, $modalInstance, items) {

  $scope.items = items;
  $scope.selected = {
    item: $scope.items[0]
  };

  $scope.ok = function () {
    $modalInstance.close($scope.selected.item);
  };

  $scope.cancel = function () {
    $modalInstance.dismiss('cancel');
  };
});

这是我的ui.bootstrap.min.js注射:

enter image description here

现在问题在于:

我认为在 pages / home.blade.php 文件中,<script></script>代码之间存在问题代码。

检查出来:

Problem

这是我得到的错误(抱歉,默认语言是土耳其语)

enter image description here

就像我说的那样,我的目的是使用 UI Bootstrap和laravel blade模板。

提前致谢!

1 个答案:

答案 0 :(得分:1)

这有点不清楚这是否只是 问题,但Angular和Blade模板都使用相同的标记来表示插值区域的开始/结束,即{{和{{ 1}}。如果要将它们一起使用,则需要将其中一个更改为其他内容,否则Blade角色代码将由服务器上的Blade解释,并导致500服务器错误。

在Blade中,这看起来像:

}}

在Angular中,它看起来像这样:

Blade::setContentTags('<%', '%>'); 
Blade::setEscapedContentTags('<%%', '%%>');