我正在尝试将 AngularJS 与 Rails 连接起来。我的观点有些问题。他们没有在
中进行渲染正在获取我的 View ,但出现错误 [HTTP/1.1 404 Not Found]
我收到这个是为了回复first.html https://github.com/sourabh-garg/vegeta/blob/master/response%20error.html
在我尝试加载的 app/assets/templates/first.html 中。
app/views/application/index.html.erb 有我的索引文件
路由 root 'application#index'
App.js
var app = angular.module('myapp', ['ui.router'])
.config(function config($stateProvider){
$stateProvider.state("index", {
url : "",
controller : "FirstCtrl as first",
templateUrl : "first.html"
})
$stateProvider.state("second", {
url : "/second",
controller : "SecondCtrl as second",
templateUrl : "second.html"
})
})
.directive('elem', function () {
return {
restrict: 'E',
templateUrl: "templates/second.html"
};
})
.filter('reverse', function(){
return function(text){
return text.split('').reverse().join('');
}
})
.service("greeting", function Greeting(){
var greeting = this;
greeting.message = "Default";
})
.service('Data', [function () {
return {message: "You are a awesome"}
}])
.controller('FirstCtrl', function($scope, greeting, Data){
var first = this;
first.greeting = greeting;
first.data = Data;
first.reversed = function(message){
return message.split('').reverse().join('');
};
})
.controller('SecondCtrl', function($scope, greeting){
var second = this;
second.greeting = greeting;
});
最佳答案
1) 您正在使用gem angular-rails-templates
。
您不需要将模板模块注入(inject)到您的 Angular 应用程序中吗?
angular.module('myapp', ['ui.router', 'templates'])
2) 在文件结构 app/assets/javascripts/
中,第 5 行的 application.js
文件,查看是否更改 //= require_tree 。
到 //= require_tree ../templates
更正链接。
资源: angular-rails-template: include templates in rails assets pipeline
关于javascript - 为什么我的 html 页面没有在 <ui-view> 中渲染?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37123714/