Using the $http service to make requests to remote servers.

categories-model.js:

angular.module('eggly.models.categories', [

])
.service('CategoriesModel', function ($http, $q) {
var CategoriesModel = {},
URLS = {
FETCH: 'data/categories.json'
},
categories; function extract(result) {
return result.data;
} function cacheCategories(result) {
categories = extract(result);
return categories;
} CategoriesModel.getCategories = function() {
return (categories) ? $q.when(categories) : $http.get(URLS.FETCH).then(cacheCategories);
}; return CategoriesModel;
})
;

bookmarks-model.js

angular.module('eggly.models.bookmarks', [

])
.service('BookmarksModel', function($http){
var model = this,
URLS = {
FETCH: 'data/bookmarks.json'
},
bookmarks; function extract(result) {
return result.data;
} function cacheBookmarks(result) {
bookmarks = extract(result);
return bookmarks;
} model.getBookmarks = function() {
return $http.get(URLS.FETCH).then(cacheBookmarks);
};
}) ;

[Angular-Scaled Web] 8. Using $http to load JSON data的更多相关文章

  1. 一个解决过程:Servlet [某路径xxx] in web application [/项目xxx] threw load() exception和java.lang.ClassNotFoundException XXX

    Servlet [某路径xxx] in web application [/项目xxx] threw load() exception和java.lang.ClassNotFoundException ...

  2. 混合开发 Hybird Ionic Angular Cordova web 跨平台 MD

    Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...

  3. 【Angular JS】正确调用JQuery与Angular JS脚本 - 修复Warning: Tired to load angular more than once

    自己正在做一个小网站,使用Angular JS + Express JS + Mongo DB,在开发过程中,遇到一些问题,所以整理出来.希望对大家都有帮助. 这是今天解决的一个问题,Angular ...

  4. IIS "rewrite.dll failed to load. The data is the error." 错误解决方法

    在Windows 10 build 17133.73上部署一个较老版本的ASP.NET 2.0程序,访问时候出现: Service Unavailable HTTP Error 503. The se ...

  5. Web 开发人员必备的随机 JSON 数据生成工具

    在 Web 开发中,经常会需要一些测试数据来测试接口或者功能时候正确.JSON Generator 就是这样一款生成随机 JSON 数据的在线工具,Web 开发人员必备,记得收藏和分享啊. 您可能感兴 ...

  6. Python load json file with UTF-8 BOM header - Stack Overflow

    Python load json file with UTF-8 BOM header - Stack Overflow 3 down vote Since json.load(stream) use ...

  7. failed to load response data

    当需要根据后台传回地址跳转页面时 即使使用preserve log 可以查看上一个页面获取地址请求,但是此时请求返回值为failed to load response data 当关闭页面跳转可以查看 ...

  8. angular 学习笔记(3) ng-repeat遍历json并且给样式

    视图: <div ng-app="myapp" ng-controller="myctrl"> <ul> <li ng-repea ...

  9. angular 学习笔记(2) ng-repeat遍历json

    视图: <div ng-app="myApp" ng-controller="myCtrl"> <ul> <li ng-repea ...

随机推荐

  1. [Everyday Mathematics]20150113

    设 $f\in C^2(0,+\infty)$ 适合 $$\bex \lim_{x\to 0^+}f'(x)=-\infty,\quad \lim_{x\to 0^+}f''(x)=+\infty. ...

  2. Android主题theme和风格style总结

    用到了Android的主题和风格,感觉很多地方需要总结和记录下来.其实主题和风格是有很大的作用的,特别是界面要求比较高的客户端. Style:是一个包含一种或者多种格式化属性的集合,我们可以将其用为一 ...

  3. python学习之self,cls,staticmethod,classmethod

    一.总体说明 python类里会出现这三个单词,self和cls都可以用别的单词代替,类的方法有三种, 一是通过def定义的 普通的一般的,需要至少传递一个参数,一般用self,这样的方法必须通过一个 ...

  4. bzoj 2594 [Wc2006]水管局长数据加强版(LCT+最小生成树)

    [深坑勿入] [给个链接] http://blog.csdn.net/popoqqq/article/details/41348549 #include<cstdio> #include& ...

  5. js笔记--json

    1.什么事json: json是指javascript对象表示法(javascript Object Notation), json是轻量级的文本数据交换格式: json独立于语言: json具有自我 ...

  6. Tkinter教程之Text篇(3)

    本文转载自:http://blog.csdn.net/jcodeer/article/details/1811348 '''Tkinter教程之Text篇(3)''''''14.自定义tag的两个内置 ...

  7. 【转】VC6.0附带小工具软件一览

    )ActiveX Control Test Container称为"ActiveX 控件测试容器",顾名思义,此工具的主要功能就是测试ActiveX 控件,可以通过改变Active ...

  8. [Hive - LanguageManual] Sampling

    Sampling Syntax Sampling Bucketized Table Block Sampling Sampling Syntax  抽样语法 Sampling Bucketized T ...

  9. hadoop2.7【单节点】单机、伪分布、分布式安装指导

    问题导读 1.从本文部署实际部署,总结本地模式.伪分布.分布式的区别是什么?2.单机是否是伪分布?3.本地模式是否可以运行mapreduce? 来源:about云 http://www.aboutyu ...

  10. DelphiXE8怎么使用调试模式

    需求:在开发Android程序时,大家一直是使用ShowMessage.其实XE是支持下断点的. 操作: 1.小米手机用USB线,连到电脑上. 2.小米手机-设置-关于手机-"MIUI版本& ...