【问题标题】:Angular ng-include not working with laravel views : blade templateAngular ng-include 不适用于 laravel 视图:刀片模板
【发布时间】:2018-06-18 14:21:49
【问题描述】:

我对 angularjs+blade 模板混合不太熟悉。 laravel 的刀片模板不渲染 ng-include (angularjs) html 文件。或者是否有必要将所有包含的 html 转换为刀片文件?对于核心 PHP,这不是问题。在这种情况下工作的方法是什么?

  <title>{{ config('app.name', 'Nepstralia')}}</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <link rel="stylesheet" href="custom.css">
  <link rel="stylesheet" href="assets/css/Footer-with-map.css">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  <script src = "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>




<ng-include src="'nav.html'"> </ng-include>
<!-- <div id="toptarget"> &nbsp; </div><br> -->


<ng-include src="'carousel.html'"> </ng-include>

刀片模板中没有加载 ng-included。如何在刀片中使用角度 ng-include ?

【问题讨论】:

  • 试试&lt;div ng-include src="'carousel.html'"&gt;&lt;/div&gt;

标签: angularjs laravel


【解决方案1】:

首先您必须通过ng-app 声明 Angular 应用程序,然后尝试以下操作: index.html:

  <!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="utf-8" />
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <link rel="stylesheet" href="custom.css">
    <link rel="stylesheet" href="assets/css/Footer-with-map.css">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body ng-app>





<div ng-include="'nav.html'"> </div>
<!-- <div id="toptarget"> &nbsp; </div><br> -->


<div ng-include="'carousel.html'"> </div>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>

</body>
</html>

carousel.html:

<h1>123</h1>

nav.html

<h2>145</h2>

如果它不工作可能是你的 src 是错误的。

【讨论】:

  • 用过 但一直没用
  • 你把 ng-include 放在 div 标签里了吗?
  • 是的,仍然无法正常工作:
    可能是我遗漏了什么?我的设计包括使用 angularjs。我不喜欢使用刀片 @include()。我认为它应该可以工作,因为它是前端。
  • 我会一步一步更新我的答案,如果可行,请检查答案。谢谢
  • 我将此标记为答案,因为权限/laravel 存在问题。感谢@Aref Zamani 的回答
猜你喜欢
相关资源
最近更新 更多
热门标签