[英]Angular Routing in Rails (shows blank page)
Hello I'm trying to include Angular in my rails app and I'm getting a blank html here's my code 您好,我试图将Angular包含在我的rails应用程序中,但得到的是空白HTML,这是我的代码
app/views/index.html.erb 应用/视图/ index.html.erb
<body>
<div ng-controller="MainController">
<ng-view></ng-view>
</div>
<script type="text/ng-template" id="view.html">
<div ng-controller="MainController">This is the view with some data here: {{ somedata }}</div>
</script>
</body>
assets/javascript/static.js 资产/ JavaScript的/ static.js
var app = angular.module('app', ['ngRoute']);
app.controller('MainController', function($scope) {
$scope.somedata = "This is some data!"
});
app.config(function($routeProvider) {
$routeProvider
.when('/', {templateUrl: 'view.html'})
})
application.js 的application.js
//= require angular-resource
//= require angular
//= require_tree .
routes.rb 的routes.rb
Rails.application.routes.draw do
root 'static#index'
get '*path' => 'static#index'
end
now I whenever I go to server I see a blank page. 现在,无论何时我去服务器,我都会看到一个空白页。 no errors. 没有错误。 I'm using the 'angularjs-rails' gem and it seemed to work fine until I added the angular routes. 我使用的是“ angularjs-rails” gem,在添加角度路线之前,它似乎工作正常。 Could you please point out where is the error. 您能否指出错误出在哪里。
Try It : 试试吧 :
In your static.js 在您的static.js中
app.config(function($routeProvider, $locationProvider) {
$routeProvider
.when('/', {templateUrl: 'view.html'})
$locationProvider.html5Mode({
enabled: true,
requireBase: false,
rewriteLinks: true
});
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.