【发布时间】:2016-02-27 02:41:53
【问题描述】:
我在我的 symfony 应用程序中安装了 angularJS,我尝试从我的 angular-module 加载我的 html 文件:
文件结构:
app
bin
bower_components
src
vendor
web
html
index.html
app.js
我的 app.js:
var app = angular.module('app', ['ngRoute']);
app.config(['$routeProvider', function($routeProvider) {
$routeProvider.
when('/', {
templateUrl: 'web/html/index.html',
controller: 'IndexCtrl'
}).
...
}]);
app.controller("IndexCtrl", ["$scope", function ($scope) {
$scope.data = [
{ id: 1, name: "adfsdf"},
{ id: 2, name: "Susdfsdfsi"},
{ id: 3, name: "Resdfiner"},
{ id: 4, name: "sdfs"}
];
}]);
但是当加载 html 文件时,我得到“404 - Not Found”。
我已经尝试过相对路径和绝对路径:
// absolute
templateUrl: 'html/index.html',
// relative
templateUrl: 'web/html/index.html',
两者都不起作用。
有人可以帮我解决这个问题吗?
谢谢和问候!
【问题讨论】:
-
我能够在 Plunkr (plnkr.co/edit/pzge58p6b3nfUylWPsDM) 中启动并运行它,所以我不得不想象你的路径在某种程度上是不正确的。
-
那是什么问题,只要打开开发工具并检查什么请求失败,然后相应地调整路径。
-
我认为主要问题是 symfony2 中的配置,我必须编写一个“.htaccess” - 文件可能吗?
-
您是否能够在 Angular 之外访问这些模板(即只需打开浏览器并导航到该资源 URL)?如果不是,那么是的,您可能有一些限制。
-
我无法在 Angular 之外访问这些模板(即在 url 中),我应该如何继续?
标签: angularjs symfony routing http-status-code-404 ngroute