[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- ...
随机推荐
- SublimeText3 初探(工欲善其事,必先利其器)
告别2015,迎来了2016.祝看到这篇博客的兄弟们都猴年发财,人生走上另一个高度. 新年新气象,猴年我会常常来更新自己的博客,希望能接触到更多的园友. sublime text3 和atom 各有各 ...
- 【LeetCode】96 - Unique Binary Search Trees
Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For examp ...
- static用法总结
C++的static有两种用法:面向过程程序设计中的static和面向对象程序设计中的static.前者应用于普通变量和函数,不涉及类:后者主要说明static在类中的作用. 一.面向过程设计中的st ...
- win7 提示"Windows 无法连接到System Event Notification Service服务......"的解决办法
登录win7系统,突然出现如图1的提示,无线网络中断,不能上网,多次插拔无线网卡问题依然. 图1 解决过程如下: 1.检查网卡硬件状况,在设备管理器中查看网卡现象正常,排除网卡硬件故障. 2.查看服务 ...
- android 运行 python
Jython is an implementation of the Python programming language designed to run on the Java platform. ...
- Clean Code第三章<函数>
1.方法不要写太长,如果太长,抽取其中的逻辑到新的方法中 bad good 2.函数只做一件事 如果做了多件事,要在方法名里体现出来 3.每个函数一个抽象层级 4.函数名可以长一些,比长注释好 5.方 ...
- vimdiff
[vimdiff] 启动方法 首先保证系统中的diff命令是可用的.Vim的diff模式是依赖于diff命令的.Vimdiff的基本用法就是: # vimdiff FILE_LEFT FILE_RIG ...
- stm32F4各个库文件的作用分析
system_stm32f4xx.c:This file contains the system clock configuration for STM32F4xx devices. /** **** ...
- IE浏览器在虚拟机中无法正常显示字符
今天在win7虚拟机中安装IE10之后,打开任何页面都无法显示文字,自己找了一些资料也没有什么发现,虚拟机其他的程序都能很好的工作,只有IE10有问题,于是初步怀疑是IE10设置的问题.于是打开IE的 ...
- Eclipse报错 Unable to execute dex: Multiple dex files define Lcom/kenai/jbosh/AbstractAttr
这个错误时jar包重复造成的!! 看看有没有多的private Libary 删除即可!!!