【发布时间】:2016-05-09 19:16:09
【问题描述】:
我正在尝试用 rails 连接 angularjs。我的观点有一些问题。他们没有得到渲染
正在获取我的视图,但出现错误 [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;
});
【问题讨论】:
-
“/second”是否出现并正常工作?
-
不,不是。我看到一个错误“templates/first.html”它应该只是“first.html”。即使在纠正之后。它不工作。
-
您确定
templateUrl: "templates/second.html"指向正确的位置吗?不是templateUrl: "/app/assets/templates/second.html"? -
acutally 它只是“first.html”或“second.html”,因为我正在使用 rails-angular-template gem 它会自动查看 /app/assets/templates/
标签: javascript ruby-on-rails angularjs