1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Access Data From HTML</title>
  5. </head>
  6. <body ng-app="app" ng-controller="TodoCtrl as todoCtrl">
  7.  
  8. <div ng-repeat="todo in todoCtrl.todos">
  9. {{todo.item}}
  10. </div>
  11. <form>
  12. <input type="text" ng-model="newTodo"/>
  13. <input type="submit" ng-click="todoCtrl.addTodo(newTodo)"/>
  14. </form>
  15. <script src="bower_components/angular/angular.js"></script>
  16. <script src="app.js"></script>
  17. </body>
  18. </html>
  1. /**
  2. * Created by Answer1215 on 11/29/2014.
  3. */
  4.  
  5. function ToDoServices($q, $timeout) {
  6.  
  7. var ToDoServices = {};
  8.  
  9. ToDoServices.getTodos = function() {
  10. return $q(function(resolve, reject) {
  11. $timeout(function() {
  12. resolve(
  13. {
  14. todos: [
  15. {item: "Clean room", done: false},
  16. {item: "Eat lunch", done: false},
  17. {item: "Wash car", done: false}
  18. ]
  19. }
  20. )
  21. }, 500);
  22. });
  23. };
  24.  
  25. ToDoServices.addTodo = function(item) {
  26.  
  27. this.todos.push({item: item, done: false})
  28. }
  29.  
  30. return ToDoServices;
  31. }
  32.  
  33. function TodoCtrl(ToDoServices) {
  34.  
  35. var vm = this;
  36. vm.todos = [];
  37.  
  38. vm.getTodos = ToDoServices.getTodos;
  39. vm.addTodo = ToDoServices.addTodo;
  40.  
  41. vm.getTodos(vm.isReject).then(function(res) {
  42. vm.todos = res.todos;
  43. });
  44. }
  45.  
  46. angular.module("app", [])
  47. .factory("ToDoServices", ToDoServices)
  48. .controller("TodoCtrl", TodoCtrl);

[AngularJS] Accessing Data in HTML -- controllerAs, using promises的更多相关文章

  1. 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 ...

  2. 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. ...

  3. 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 ...

  4. 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 ...

  5. [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 ...

  6. AngularJS - Passing data between pages

    You need to create a service to be able to share data between controllers. app.factory('myService', ...

  7. [AngularJS] Accessing Services from Console

    Using the Chrome console, you can access your AngularJS injectable services. This is down and dirty ...

  8. AngularJS Tabular Data with Edit/Update/Delete

    效果 首先,我们先建立一些数据,当然你可以从你任何地方读出你的数据 var app = angular.module('plunker', ['ui.bootstrap']); app.control ...

  9. angularjs post data

    //post json 时收不到数据,目前只找到方法post form形式的key-value值 //关键是设置  headers: { 'Content-Type': 'application/x- ...

随机推荐

  1. 安装linux操作系统--浪潮服务器

    一直都是在虚拟机上进行安装linux操作系统,在服务器上安装的很少,也没有碰到过没找到驱动的情况,例如什么raid卡驱动,网卡驱动等异常情况的发生. 这次安装了两台服务器,浪潮的提供的服务器,硬盘是两 ...

  2. linq性能剖析

    Orcas(VS2008&Framework3.5)给我们带来了很多令人兴奋的新特性,尤其是LINQ的引进,可以说方便了一大批开发 人员和框架设计人员.过去,当我们使用O/RMapping的一 ...

  3. 30个有关Python的小技巧

    从我开始学习python的时候,我就开始自己总结一个python小技巧的集合.后来当我什么时候在Stack Overflow或者在某个开源软件里看到一段很酷代码的时候,我就很惊讶:原来还能这么做!,当 ...

  4. SharePoint咨询师之路:备份和恢复系列二 - 备份服务器场

    本系列包括: 备份服务器场和配置 备份web和服务应用程序 备份内容数据库 备份网站集 备份自定义项 根据“SharePoint咨询师之路:备份和恢复系列--制定备份计划”我们制定了一下备份计划如下: ...

  5. C++11散列表

    [C++11散列表] 散列表对应于C++03中的hash_xxx,分为set和map两种 上述的类型将满足对一个容器类型的要求,同时也提供访问其中元素的成员函数: insert, erase, beg ...

  6. POJ 3347 Kadj Squares

    Kadj Squares Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 2132   Accepted: 843 Descr ...

  7. .net 学习资源(转)

      名称:快速入门地址:http://chs.gotdotnet.com/quickstart/描述:本站点是微软.NET技术的快速入门网站,我们不必再安装.NET Framework中的快速入门示例 ...

  8. Objective-C 学习记录6--dictionary

    1.NSDictionary 和NSMutableDictionary NSDictionary dictionaryWithObjectsAndKeys:~,nil 使用键值对创建字典,用nil标志 ...

  9. 记一次PHP项目部署过程

    首先介绍一下项目的基本情况:使用PHP语言开发,数据库用的是MySQL 5.5,HTTP服务器用的是Apache 2.2.早上十点到机房看了看服务器的基本情况:Windows 2000操作系统,没有安 ...

  10. VS2010 Web网站发布详解

    1.项目某一网站 右键 发布 出来对话框后 发布方法选择文件系统,发布前删除所有现有文件(选择此项) ,然后点击发布就OK了. 2.之后如果只修改aspx页面,编译下无需再次发布,如果修改了类库或.c ...