Hello I'm trying to include Angular in my rails app and I'm getting a blank html here's my code
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
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. Could you please point out where is the error.
Try It :
In your static.js
app.config(function($routeProvider, $locationProvider) {
$routeProvider
.when('/', {templateUrl: 'view.html'})
$locationProvider.html5Mode({
enabled: true,
requireBase: false,
rewriteLinks: true
});
})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.