[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- ... 
随机推荐
- Android的主要组件
			(一)Activity(活动) 作用:提供可视化用户界面 只能通过setContentView(View)来显示指定组件 View组件是所有UI控件.容器控件的基类,View组件就是android应用 ... 
- 【LeetCode】190 & 191 - Reverse Bits & Number of 1 Bits
			190 - Reverse Bits Reverse bits of a given 32 bits unsigned integer. For example, given input 432615 ... 
- Package inputenc Error: Unicode char \u8:  not set up for use with LaTeX.
			用TexStudio编辑文档时,不知是多加了空格还是啥,总是提示如下错误: Package inputenc Error: Unicode char \u8: not set up for use w ... 
- 自己使用python webob,paste.deploy,wsgi总结
			paste.deploy就是一个可以配置wsgi_app的工具,可以让服务器运行时,按照配置文件执行一系列的程序.需要使用.ini配置文件. (1)这里补充一下当时没看到的配置文件 1.[app:ma ... 
- 不定高度的div背景或背景图片不显示问题
			在使用div+css进行网页布局时,如果外部div有背景颜色或者边框,而不设置其高度,在IE浏览器下显示正常.但是使用Firefox/opera浏览时却出现最外层Div的背景颜色和边框不起作用的问题. ... 
- Tcl之group arguments
			1 doubel quotes This allows substitutions to occur within the quotations - or "interpolation&qu ... 
- pku3659 Cell Phone Network
			http://poj.org/problem?id=3659 树状DP,树的最小点覆盖 #include <stdio.h> #include <vector> #define ... 
- redhat 挂载 iso文件 提示 mount :not a directory
- 【多线程】Java并发编程:Lock(转载)
			原文链接:http://www.cnblogs.com/dolphin0520/p/3923167.html Java并发编程:Lock 在上一篇文章中我们讲到了如何使用关键字synchronized ... 
- 详解Android定位
			相信很多的朋友都有在APP中实现定位的需求,今天我就再次超炒冷饭,为大家献上国内开发者常用到的三种定位方式.它们分别为GPS,百度和高德,惯例先简单介绍下定位的背景知识. 什么是GPS定位.基站定位和 ... 
