ng-view重复我的application.html.erb中写的内容

时间:2013-10-27 07:06:42

标签: ruby-on-rails angularjs angularjs-ng-repeat

我正在使用带有Rails应用程序的Angular&我application.html.erb文件夹中的app/views/layout如下所示:

<!DOCTYPE html>
<html>
<head>
  <title>Fmtemp</title>
  <%= stylesheet_link_tag    "application", :media => "all" %>
  <%= csrf_meta_tags %>
</head>
<body ng-app="fmview">
<%= yield %>
<%= javascript_include_tag "application" %>
</body>
</html>

我还有一个名为app/views/fmtest的文件夹index.html 编码为:

<h1> Greetings from FMView App </h1>
<a href="#/list"> List </a>&nbsp;
<a href="#/grid"> Grid </a>
<div ng-view></div>

现在我的应用程序的HTML呈现很奇怪:

<html>
    <head>
        <style type="text/css">@charset "UTF-8";[ng\:cloak],[ng-cloak],[data-ng-cloak],[x-ng-cloak],.ng-cloak,.x-ng-cloak,.ng-hide{display:none !important;}ng\:form{display:block;}</style>
        <title>Fmtemp</title>
        <link href="/assets/application.css?body=1" media="all" rel="stylesheet" type="text/css">
        <link href="/assets/fmview.css?body=1" media="all" rel="stylesheet" type="text/css">
        <meta content="authenticity_token" name="csrf-param">
        <meta content="Vwo3zN2lK8hvLPQcV3llnGnvgNqCLaHHsBubSRaYueg=" name="csrf-token">
        <style type="text/css"></style></head>
    <body ng-app="fmview" class="ng-scope" style="">
        <h1> Greetings from FMView App </h1>
        <a href="#/list"> List </a>&nbsp;
        <a href="#/grid"> Grid </a>
        <!-- ngView -->
        <div ng-view="" class="ng-scope">
        <title>Fmtemp</title>
        <link href="/assets/application.css?body=1" media="all" rel="stylesheet" type="text/css">
        <link href="/assets/fmview.css?body=1" media="all" rel="stylesheet" type="text/css">
        <meta content="authenticity_token" name="csrf-param">
        <meta content="Vwo3zN2lK8hvLPQcV3llnGnvgNqCLaHHsBubSRaYueg=" name="csrf-token">


        <h2>List View Welcomes you</h2>

        <script src="/assets/angular-1.2.js?body=1" type="text/javascript"></script>
        <script src="/assets/angular-route.min.js?body=1" type="text/javascript"></script>
        <script src="/assets/fmview.js?body=1" type="text/javascript"></script>
        <script src="/assets/application.js?body=1" type="text/javascript"></script>


        </div>
        <script src="/assets/angular-1.2.js?body=1" type="text/javascript"></script>
        <script src="/assets/angular-route.min.js?body=1" type="text/javascript"></script>
        <script src="/assets/fmview.js?body=1" type="text/javascript"></script>
        <script src="/assets/application.js?body=1" type="text/javascript"></script>
    </body>
</html>

这些JS和Sylesheets一次又一次地被包含在内。

现在,当我尝试在application.html.erb中添加任何标头或任何代码时 它只是在ng-view div ...

中重复出现

尝试在这里和那里移动<yield>,但它只是一样,有问题。

2 个答案:

答案 0 :(得分:1)

您的角度模板在哪里提供?

如果通过路径/控制器/视图(而不是公共目录)提供服务,它们将与另一个布局模板一起提供,从而复制您在此处显示的布局 - 渲染页面的1个布局+ 1个布局ng-view模板网址。

要解决此问题,请将以下内容添加到您的ng-view模板正在服务的controller.rb文件中。

layout false

或者从公共文件夹中提供角度模板。

答案 1 :(得分:0)

尝试此更改;

<!DOCTYPE html>
<html ng-app="fmview">
<head>
  <title>Fmtemp</title>
  <%= stylesheet_link_tag    "application", :media => "all" %>
  <%= csrf_meta_tags %>
  <%= javascript_include_tag "application" %>
</head>
<body>
<%= yield %>
<div ng-view></div>
</body>
</html>