[Angular-Scaled Web] 8. Using $http to load JSON data
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的更多相关文章
- 一个解决过程: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 ...
- 混合开发 Hybird Ionic Angular Cordova web 跨平台 MD
Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...
- 【Angular JS】正确调用JQuery与Angular JS脚本 - 修复Warning: Tired to load angular more than once
自己正在做一个小网站,使用Angular JS + Express JS + Mongo DB,在开发过程中,遇到一些问题,所以整理出来.希望对大家都有帮助. 这是今天解决的一个问题,Angular ...
- 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 ...
- Web 开发人员必备的随机 JSON 数据生成工具
在 Web 开发中,经常会需要一些测试数据来测试接口或者功能时候正确.JSON Generator 就是这样一款生成随机 JSON 数据的在线工具,Web 开发人员必备,记得收藏和分享啊. 您可能感兴 ...
- 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 ...
- failed to load response data
当需要根据后台传回地址跳转页面时 即使使用preserve log 可以查看上一个页面获取地址请求,但是此时请求返回值为failed to load response data 当关闭页面跳转可以查看 ...
- angular 学习笔记(3) ng-repeat遍历json并且给样式
视图: <div ng-app="myapp" ng-controller="myctrl"> <ul> <li ng-repea ...
- angular 学习笔记(2) ng-repeat遍历json
视图: <div ng-app="myApp" ng-controller="myCtrl"> <ul> <li ng-repea ...
随机推荐
- [Everyday Mathematics]20150122
设 $f:[0,1]\to [0,1]$. (1). 若 $f$ 连续, 试证: $\exists\ \xi\in [0,1],\st f(\xi)=\xi$. (2). 若 $f$ 单调递增, 试证 ...
- java web 学习九(通过servlet生成验证码图片)
一.BufferedImage类介绍 生成验证码图片主要用到了一个BufferedImage类,如下:
- 11、WebView 使用总结
<WebView android:id="@+id/webview" android:background="@color/white" android: ...
- 24、AR技术
什么是AR 在介绍增强现实(AR)之前,需要先说说虚拟现实(VR) 虚拟现实是从英文Virtual Reality 一词翻译过来的,简称VR.VR 技术是采用以计算机技术为核心的技术,生成逼真的视.听 ...
- ant 安装过程中问题记录
最近在本机安装ant过程中出现一些问题,在此记录一下. 1.Unable to locate tools.jar. Expected to find it in C:/Program Files/Ja ...
- lightoj 1023
题意:让你输出前N个大写字母的前K个排列,按字典序,很水,直接dfs. #include<cstdio> #include<string> #include<cstrin ...
- MorningSale 使用帮助
待添加 http://121.37.42.173:8080/morningsale
- 使用JSP处理用户注册和登陆
1. 这是一个JSP实例,由四个JSP页面组成,处理用户的注册和登陆信息2. 首先是login.jsp,代码如下:<html><center><form method=g ...
- support vector regression与 kernel ridge regression
前一篇,我们将SVM与logistic regression联系起来,这一次我们将SVM与ridge regression(之前的linear regression)联系起来. (一)kernel r ...
- Java-note-字符串转换为基本值
Integer.parseInt() and Double.parse.double() 例: Integer.parseInt("123") 得到常量123