阅读AngularJS本地文件 [英] Read local file in AngularJS

查看:159
本文介绍了阅读AngularJS本地文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用RequireJS和骨干,并使用 requirejs /文工作,的 requirejs-插件来加载本地JSON文件,我通常使用的配置。

I used to work with RequireJS and Backbone and used requirejs/text and requirejs-plugins to load local json files I normally use for configuration.

怎样才能用AngularJS达到同样的?

How does one achieve the same with AngularJS?

每个人似乎都建议使用的$ HTTP,但是这是唯一的方法?
我真的需要做20个电话,如果我有20个配置文件?

Everyone seems to suggest to use $http, but is this the only way? Do I really need to make 20 calls if I have 20 configuration files?

也许像 NG恒定是preferred的方式?

Maybe something like ng-constant is the "preferred" way?

推荐答案

你能使用jQuery的的getJSON 功能?

Can you use jQuery's getJSON function?

例如是这样的:

$.getJSON("config-1.json", function( data ) {
    // do whatever you want
});

这篇关于阅读AngularJS本地文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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