是否可以在没有 Web 服务器的情况下使用 ng-include? [英] Is it possible to use ng-include without web server?

查看:32
本文介绍了是否可以在没有 Web 服务器的情况下使用 ng-include?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行一个仅包含一个文件的 AngularJS 应用

在网络服务器下运行时有效.但是,如果仅通过从文件资源管理器(即不是从 Web 服务器)双击运行 Web 应用程序,则它不包含该文件

ng-include 是否在 Web 服务器之外工作?我检查了 Chrome 上的网络状态,它在方法上显示OPTIONS,在状态上显示加载取消

解决方案

一种解决方法是内联您的模板:

小提琴.

这会将您的模板放入 Angular 的模板缓存中.当处理 ng-include 指令时,Angular 首先检查缓存.

I'm running an AngularJS app which merely include a file

<div ng-include src="'sample.html'"></div>

That works when run under web server. But if the web app is run from merely double clicking from file explorer (i.e. not from web server), it doesn't include the file

Does ng-include works outside of web server? I checked the Network status on Chrome, it says OPTIONS on Method, and Load cancelled on Status

解决方案

One workaround is to inline your templates:

<script type="text/ng-template" id="sample.html">
  <div>This is my sample template</div>
</script>

Fiddle.

This puts your template into Angular's template cache. When an ng-include directive is processed, Angular checks the cache first.

这篇关于是否可以在没有 Web 服务器的情况下使用 ng-include?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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