javascript - How to assign Angular Service object to $scope object -
i'll try keep simple possible.
i have controller state 1 saves form object(with several fields) service array upon submit , proceeds state 2.
on next page there button go state 1. want user able go , ng-model fields populate saved. function have in controller.
var setform = function(){ if (estatesvc.forms[0]){ $scope.personalform = estatesvc.forms[0]; } } setform()
using console.log($scope.personalform)
. able see estatesvc.forms[0]
assigned $scope.personalform
. but, example, ng-model="personalform.example"
input field not update estatesvc.forms[0].example
.
controller
.controller('personalctrl', function ($scope, estatesvc) { $scope.personalform = {}; var setform = function(){ if (estatesvc.forms[0]){ $scope.personalform = estatesvc.forms[0] } } setform() $scope.addform = function(form, number){ estatesvc.addform(form, number) } });
service
.service('estatesvc', function () { // angularjs instantiate singleton calling "new" on function var estateobject = {}; estateobject.forms = [] estateobject.addform = function(form, number){ estateobject.forms[number] = form } return estateobject });
any suggestions on how assign service object $scope object , have ng-model populate?