繁体   English   中英

Rails中的角度布线(显示空白页)

[英]Angular Routing in Rails (shows blank page)

您好,我试图将Angular包含在我的rails应用程序中,但得到的是空白HTML,这是我的代码

应用/视图/ 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>

资产/ 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,在添加角度路线之前,它似乎工作正常。 您能否指出错误出在哪里。

试试吧 :

在您的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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM