2013-10-27 33 views
1

我用角與我application.html.erbapp/views/layout文件夾中的Rails應用程序&看起來是這樣的:NG-視圖重複寫的是什麼,我application.html.erb

<!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格重複被...

試圖在這裏和那裏走動<yield>但它是一樣的,有問題的。

回答

1

您的角模板從哪裏提供?

如果通過routes/controllers/view(而不是公共目錄)提供它們,它們將與另一個佈局模板一起提供,從而像您在此顯示的那樣複製佈局 - 1渲染頁面佈局+ 1佈局爲ng-view模板url。

要解決此問題,請將以下內容添加到您的ng-view模板所提供的controller.rb文件中。

layout false 

或者從公用文件夾中提供角模板。

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> 
+0

你的意思是:嘗試使整個HTML頁面爲Angular的fmview App? – mayankcpdixit