angularjs - Angular, testing none-persistent data storage locally -
i'm pretty new angularjs, , i'm looking way (which might remind ember fixture
) store none-persistent data testing purposes, before integration server-side.
i try store data in 2 ways 1 regular copy , the other using post
.
index.html
:
<body ng-controller="phonelistctrl"> <p>phone list</p> <ul> <li ng-repeat="phone in phones"> {{phone.name}} <p>{{phone.snippet}}</p> </li> </ul> <p>add new</p> <form> name: <input type="text" ng-model="phone.name" /><br /> snippet:<input type="text" ng-model="phone.snippet" /><br /> <button ng-click="add(phone)">save regular</button> <br /> <button ng-click="addrest(phone)">save rest</button> <br /> </form> </body>
javascript
:
function phonelistctrl($scope,$http) { $scope.phones = [ {"name": "nexus s", "snippet": "fast got faster nexus s."}, {"name": "motorola xoom™ wi-fi", "snippet": "the next, next generation tablet."}, {"name": "motorola xoom™", "snippet": "the next, next generation tablet."} ]; $scope.add = function(phone) { $scope.phones = angular.save(phone); }; $scope.addrest = function(phone){ $http.post('phones/phones.json', phone, {}); };
}
i use 2 functions invoked 2 different buttons store data. couldn't figure way put phones/phones.json
in jsbin, url
file contains list of phones.
in ember quite simple define model test purposes in angular cannot find way test storing locally before integration server-side.
it helpful know why see many people using resource
handle http methods when can use $http.<method>
in controller that.
Comments
Post a Comment