是否有可能采用NG-包括但Web服务器? [英] Is it possible to use ng-include without web server?

查看:149
本文介绍了是否有可能采用NG-包括但Web服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行的应用程序AngularJS仅仅其中包括文件​​

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

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

这时候在Web服务器上运行的工作。但是,如果Web应用程序是从单纯双击从文件管理器运行(即不是从Web服务器),但不包括文件

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

是否NG-包括Web服务器之外的作品?我查了Chrome的网络状态,它说的选项上的方法,和加载取消了状态

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>

小提琴

这使您的模板到角的模板缓存。当NG-include指令处理,角检查缓存第一。

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

这篇关于是否有可能采用NG-包括但Web服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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