【问题标题】:Angular Routing in Rails (shows blank page)Rails 中的角度路由(显示空白页)
【发布时间】:2015-09-04 04:49:42
【问题描述】:

您好,我正在尝试在我的 rails 应用程序中包含 Angular,但我得到了一个空白的 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'})
})

应用程序.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,它似乎工作正常,直到我添加了角度路线。请指出错误在哪里。

【问题讨论】:

    标签: javascript ruby-on-rails ruby angularjs


    【解决方案1】:

    试试看:

    在你的 static.js 中

    app.config(function($routeProvider, $locationProvider) {
    
      $routeProvider
        .when('/', {templateUrl: 'view.html'})
    
      $locationProvider.html5Mode({
        enabled: true,
        requireBase: false,
        rewriteLinks: true
      });
    })
    

    【讨论】:

    • 不幸的是不起作用。我正在使用 cloud9(这是一个云 ide),尽管我怀疑它与它有什么关系。
    猜你喜欢
    • 1970-01-01
    • 2018-02-16
    • 1970-01-01
    • 2018-02-25
    • 1970-01-01
    • 2022-03-23
    • 2020-03-27
    • 2020-02-20
    • 2016-11-24
    相关资源
    最近更新 更多