如何在angular js中存储和检索数据? [英] how to store and retrieve data in angular js?
问题描述
你能告诉我如何永久存储数据(例如本地存储)和检索数据.我想存储数据以便我再次获取.我在做客户端编程?我谷歌它说有persistance.js可以做到这一点..我们可以使用它吗?我试图做一个简单的例子来存储数据但不能这样做.我想保存学生和班级姓名的列表.这是我的 plunker:http://plnkr.co/edit/cLTIJfETGYENQyEdsu94?p=preview
can you please tell me how to store data permantly (example local storage)and retrieve data .I want to store data so that I get again .I am doing client side programing ? I google it it say there is persistance.js will do that ..can we use that ?I am try to make a simple example to store data but not able to that .I want to save list of name of student and class. here is my plunker : http://plnkr.co/edit/cLTIJfETGYENQyEdsu94?p=preview
// Code goes here
var app = angular.module('appstart', ['ngRoute']);
app.config(function($routeProvider) {
// $locationProvider.html5Mode(true);
$routeProvider
.when('/home', {
templateUrl: 'tem.html',
controller: 'ctrl'
})
.otherwise({
redirectTo: '/home'
});
});
app.controller("ctrl", function($scope) {
$scope.students = [];
$scope.add = function() {
$scope.students.push({
inputName : angular.copy($scope.inputName),
inputclass : angular.copy($scope.inputclass)
});
$scope.inputclass='';
$scope.inputName='';
}
}
);
谢谢
推荐答案
您需要一个数据库.网络存储仅用于临时用途.
You need a database. Web-storage is only for temporary things.
如果您有后端,则可以使用服务和 $http
来创建 CRUD 应用程序.
If you have a backend, you can use a service and $http
to create a CRUD application.
您使用 Angular 将数据发送到执行持久化的后端.
You use Angular to send data to the backend which does the persistence.
这篇关于如何在angular js中存储和检索数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!