当站点从本地文件系统提供服务时,角度视图是否有效? [英] Do angular views work when a site is served from the local file system?

查看:29
本文介绍了当站点从本地文件系统提供服务时,角度视图是否有效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 angular 开发应用程序.我正在 Windows 上开发本地文件系统.但是,当我启用 angular-route.js 时,每当我用浏览器点击 index.html 时,它就会转到 index.html#/C:/.

I'm using angular to develop an application. I'm developing off my local file system, on Windows. However, when I enable angular-route.js, whenever I hit index.html with my browser, it instead goes to index.html#/C:/.

我的路线定义是:

myApp.config(['$routeProvider', function($routeProvider) {
    $routeProvider.when('/', {templateUrl: 'home.html', controller: 'HomeCtrl'});
}

我认为这会导致站点中断,因为 /C:/ 不匹配任何角度路线.怎么了?我该如何解决这个问题?

I think this causes the site to break, because /C:/ doesn't match any angular routes. What's going wrong? How do I fix this?

推荐答案

用于路由 &ajax (& more) 正常工作,运行本地开发服务器;避免使用 file:// 进行开发,因为浏览器对此有不同的规则.

For routing & ajax (& more) to work properly, run a local development server; avoid use of file:// for development, since browsers have different rules for it.

yeoman + generator-angular 这样的工具会自动设置一个带有 server 任务的 gruntfile,它会运行一个 节点- 连接服务器以在本地为您的文件提供服务.

Tools like yeoman + generator-angular will automatically set up a gruntfile with a server task, which will run a node-connect server to locally serve your files.

你可以这样做

  • python: (3)python -m http.server 8001(用 2 中的 SimpleHttpServer 替换 http.server)
  • node.js + 连接
  • 红宝石 + 机架
  • 来自 angularjs 教程(使用代码"下的第 5 条)-您需要在你的系统上运行一个 http 服务器,但如果你还没有安装,你可以使用 node 运行 scripts\web-server.js,一个简单的捆绑 http 服务器."
  • python: (3)python -m http.server 8001 (replace http.server with SimpleHttpServer in 2)
  • node.js + connect
  • ruby + rack
  • From the angularjs tutorial (number 5 under "working with the code") - "You need an http server running on your system, but if you don't already have one already installed, you can use node to run scripts\web-server.js, a simple bundled http server."

评论回复:对于 phonegap,请使用 phonegap 工具.它完全按照我说的做,它运行一个本地服务器.

Response from comments: For phonegap, use the phonegap tools. It does exactly what I said, it runs a local server.

这篇关于当站点从本地文件系统提供服务时,角度视图是否有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆