[AngularJS] Accessing Data in HTML -- controllerAs, using promises
<!DOCTYPE html>
<html>
<head>
<title>Access Data From HTML</title>
</head>
<body ng-app="app" ng-controller="TodoCtrl as todoCtrl"> <div ng-repeat="todo in todoCtrl.todos">
{{todo.item}}
</div>
<form>
<input type="text" ng-model="newTodo"/>
<input type="submit" ng-click="todoCtrl.addTodo(newTodo)"/>
</form>
<script src="bower_components/angular/angular.js"></script>
<script src="app.js"></script>
</body>
</html>
/**
* Created by Answer1215 on 11/29/2014.
*/ function ToDoServices($q, $timeout) { var ToDoServices = {}; ToDoServices.getTodos = function() {
return $q(function(resolve, reject) {
$timeout(function() {
resolve(
{
todos: [
{item: "Clean room", done: false},
{item: "Eat lunch", done: false},
{item: "Wash car", done: false}
]
}
)
}, 500);
});
}; ToDoServices.addTodo = function(item) { this.todos.push({item: item, done: false})
} return ToDoServices;
} function TodoCtrl(ToDoServices) { var vm = this;
vm.todos = []; vm.getTodos = ToDoServices.getTodos;
vm.addTodo = ToDoServices.addTodo; vm.getTodos(vm.isReject).then(function(res) {
vm.todos = res.todos;
});
} angular.module("app", [])
.factory("ToDoServices", ToDoServices)
.controller("TodoCtrl", TodoCtrl);
[AngularJS] Accessing Data in HTML -- controllerAs, using promises的更多相关文章
- java.lang.IllegalStateException:Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xxx...}: java.lang.IllegalSta ...
- java.lang.IllegalStateException: Couldn't read row 1, col 0 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data fr
Android中操作Sqlite遇到的错误:java.lang.IllegalStateException: Couldn't read row 1, col 0 from CursorWindow. ...
- Accessing data in Hadoop using dplyr and SQL
If your primary objective is to query your data in Hadoop to browse, manipulate, and extract it into ...
- android 出现Make sure the Cursor is initialized correctly before accessing data from it
Make sure the Cursor is initialized correctly before accessing data from it 详细错误是:java.lang.IllegalS ...
- [AngularJS] Accessing The View-Model Inside The link() When Using controllerAs
If u using controller & controllerAs in directive, then the link()'s 4th param 'controller' will ...
- AngularJS - Passing data between pages
You need to create a service to be able to share data between controllers. app.factory('myService', ...
- [AngularJS] Accessing Services from Console
Using the Chrome console, you can access your AngularJS injectable services. This is down and dirty ...
- AngularJS Tabular Data with Edit/Update/Delete
效果 首先,我们先建立一些数据,当然你可以从你任何地方读出你的数据 var app = angular.module('plunker', ['ui.bootstrap']); app.control ...
- angularjs post data
//post json 时收不到数据,目前只找到方法post form形式的key-value值 //关键是设置 headers: { 'Content-Type': 'application/x- ...
随机推荐
- Python异常记录
1.常用异常名 AttributeError 调用不存在的方法引发的异常. EOFError 遇到文件末尾引发的异常. ImportError 导入模块出错引发的异常. IndexError 列表越界 ...
- Ubuntu14.04LTS安装记录(办公室联想台式机)
一.用UltraISO制作U盘启动器,被安装的电脑要设置成从U盘启动. 二.傻瓜式安装简体中文版 三.安装更新 sudo apt-get update sudo apt-get upgrade 四.安 ...
- Wireshark基本介绍及应用tcp
wireshark介绍 wireshark的官方下载网站: http://www.wireshark.org/ wireshark是非常流行的网络封包分析软件,功能十分强大.可以截取各种网络封包,显示 ...
- C使用FILE指针文件操作
文件的基本概念 所谓“文件”是指一组相关数据的有序集合. 这个数据集有一个名称,叫做文件名.实际上在前面的各章中我们已经多次使用了文件,例如源程序文件.目标文件.可执行文件.库文件 (头文件)等.文件 ...
- [转] Web前端优化之 图片篇
原文链接: http://lunax.info/archives/3101.html Web 前端优化最佳实践第六部分面向 图片(Image),这部分目前有 4 条规则.在最近的 Velocity 2 ...
- linux c编程 -- 线程互斥
#include <stdio.h> #include <pthread.h> #include <unistd.h> #include <stdlib.h& ...
- [翻译]HTML中不知名的语义标签
原文:http://docs.webplatform.org/wiki/tutorials/Lesser_-_known_semantic_elements HTML5中比较常用的语义元素有heade ...
- remoting blazeds 实施步骤
remoting 实施步骤 1.创建 --web project 和 -- Flex project 2.在web project 下创建 -- com.HelloRemoting: package ...
- c++类使用
一.C++定义类(注意:结束部分的分号不能省略) class 类名 { public: //公共的行为或属性 private: //公共的行为或属性 }; 注意:类的成员变量在定义时不能进行初始化, ...
- c++builder XE8 线程 Thread
thread Thread c++builder XE8 / RAD 10 Settle delphi TThread.CreateAnonymousThread(MyMethod).Start; ...