[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- ...
随机推荐
- stl 中List vector deque区别
stl提供了三个最基本的容器:vector,list,deque. vector和built-in数组类似,它拥有一段连续的内存空间,并且起始地址不变,因此 它能非常好的支持随 ...
- asp.net mvc下文件上传
典型的文件上传表单 <form action="/File" enctype="multipart/form-data" method="pos ...
- 以Akka为示例,介绍Actor模型
许多开发者在创建和维护多线程应用程序时经历过各种各样的问题,他们希望能在一个更高层次的抽象上进行工作,以避免直接和线程与锁打交道.为了帮助这些开发者,Arun Manivannan编写了一系列的博客帖 ...
- sql-labs 分享
前段时间在网上发现了一个阿三同学托管在github上的sql注入入门科普项目,感觉挺不错,在此分享一下.虽然现在有很多工具比如sqlmap可以实现自动化的sql注入,但是个人感觉如果只知其然而不知其所 ...
- <转载>linux下内存泄露查找、BUG调试
先收藏着,抽空好好看看:http://www.ibm.com/developerworks/cn/linux/l-pow-debug/ 简介 调试程序有很多方法,例如向屏幕上打印消息,使用调试器,或者 ...
- POJ1201Intervals(差分约束系统)
昨天看了下差分约数系统的含义,其实就是如果有n个变量在m个形如aj-ai>=bk条件下,求解的此不等式的方法. 而这种不等式的解法其实就是转化为图论的最小路的算法求解的.我们将上面的不等式边形后 ...
- arrayObj.splice(start, deleteCount, [item1[, item2[, . . . [,itemN]]]])
测试方法 function test(){ var arr = [0,1,2,3]; arr.splice(1,1,'a');//case console.dir(arr); } case1: arr ...
- ASP.NET MVC- 视图
关于视图的一些一些一些 一.Action指定使用视图 public ActionResult Add(string txtName, string txtContent) { return View( ...
- Fragment初步了解
fragment 1.fragment解释: 从英文上来说fragment是碎片和片段的意思,这解释的是相当到位的,因为android中的fragment就像是碎片嵌在了Activity当中的,为构造 ...
- C:结构体
结构体 构造类型:就是有基本的类型组成的 1.结构体 结构体是一种自定义的数据类型 和 int float 是一样的都可以定义变量 数组 只能存放一种类型的容器 结构体 可以存放多种数据类型 ...