您好,我正在尝试将 Angular 包含在我的 Rails 应用程序中,但我得到了一个空白 html 这是我的代码
app/views/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
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
//= require angular-resource
//= require angular
//= require_tree .
routes.rb
Rails.application.routes.draw do
root 'static#index'
get '*path' => 'static#index'
end
现在,每当我访问服务器时,我都会看到一个空白页面。没有错误。我正在使用“angularjs-rails”gem,它似乎工作正常,直到我添加了 Angular 路线。请指出错误在哪里。
最佳答案
尝试一下:
在你的 static.js 中
app.config(function($routeProvider, $locationProvider) {
$routeProvider
.when('/', {templateUrl: 'view.html'})
$locationProvider.html5Mode({
enabled: true,
requireBase: false,
rewriteLinks: true
});
})
关于javascript - Rails 中的 Angular 路由(显示空白页),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32390292/