<!DOCTYPE HTML><HTML><Head> <title>Access Data from HTML</title></Head><BodyNg-app= "App"Ng-controller= "Todoctrl as Todoctrl"><Divng-repeat= "Todo in Todoctrl.todos">{{Todo.item}}</Div><form> <inputtype= "text"Ng-model= "Newtodo"/> <inputtype= "Submit"Ng-click= "Todoctrl.addtodo (Newtodo)"/></form><Scriptsrc= "Bower_components/angular/angular.js"></Script><Scriptsrc= "App.js"></Script></Body></HTML>
/** * Created by Answer1215 on 11/29/2014.*/functiontodoservices ($q, $timeout) {varTodoservices = {}; Todoservices.gettodos=function() { return$q (function(Resolve, Reject) {$timeout (function() {resolve ({todos: [{item:
"Clean Box", done:false}, {item:"Eat Lunch", done:false}, {item:"Wash Car", Done:false} ] } ) }, 500); }); }; Todoservices.addtodo=function(item) { This. Todos.push ({item:item, done:false}) } returntodoservices;}functionTodoctrl (todoservices) {varVM = 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