我正在开发一个使用 Grails 服务器作为后端的项目(使用 asset-pipeline 作为资源管理器),并且我想使用 AngularJS 作为我的前端管理器。
我正在尝试使用 ngRoute
重新加载我的页面内容,但问题是我无法弄清楚将部分文件放在哪里,也不知道应该将什么路径设置为 templateUrl
这是我的代码:
grails-app/assets/javascripts/application.js
//= require grails-angularjs
//= require jquery
//= require_tree .
//= require_self
var myApp = angular.module('myApp', ['ngRoute']);
myApp.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/', {
templateUrl: 'test.html'
}).otherwise({
redirectTo: '/'
});
}]);
我已经尝试将 test.html 放入 web-app/partials 并将 templateUrl
设置为 static/partials/test.html
,没有更好的了。无论我使用什么,我总是会遇到 404 not found
有谁知道我的树应该是什么样子以及我应该在配置中设置什么路径?
最佳答案
我也遇到了同样的问题。最终我将 View 放入 asset/javascripts/views
这是我的 list (application.js):
//= require angular/angular
//= require angular-route/angular-route
//= require angular-resource/angular-resource
//= require angularapp
//= require_tree views
//= require_self
然后我有这个路由配置:
myApp.config(['$routeProvider', function ($routeProvider) {
$routeProvider
.when('/', {
controller: 'GioController',
templateUrl: '/angular-asset-bower/assets/views/view.html',
reloadOnSearch: false
})
.otherwise({
redirectTo : '/'
}); }])
您可以在此处查看完整的示例项目:https://github.com/gioper86/angular-asset-bower
关于javascript - Grails 下 AngularJS 应用程序中部分 html 的正确路径是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27909890/