Save the smart table content whe the button is clicked

12 views
Skip to first unread message

Vinu Prasad

unread,
Oct 19, 2017, 1:35:12 AM10/19/17
to Angular and AngularJS discussion
I am using angular4 , I want add the smart table content to a new json file when I click on the save button. Is it possible ?
In component.ts I used , 
source: LocalDataSource = new LocalDataSource();
constructor(private http : Http){
.map(response => response.json())
.subscribe(data =>{ this.obj = data
this.source.load(this.obj);});
}
SaveData()
{
alert(JSON.stringify(this.Cost));
// this is function which will active when the save button is pressed.
}

enter image description here

when click on the save button I want to overwrite the existing json1 file from the server. I there any solution for this ?? Thanks in advance..

Zlatko Đurić

unread,
Oct 20, 2017, 4:32:05 AM10/20/17
to Angular and AngularJS discussion
Not with angular alone. What you can do is pick up the changes on button click, and send those changes (or the whole new JSON) to a server that can write to files. So if your backend server is something like nginx, apache or "ng serve", you can't write that change. But if you have a Node.js, PHP, Java or something like that, you can overwrite the data.

Alternatively if this is a learning project, you might want to save (with angular) to localStorage of the browser. And on load, first check if there's data in localStorage before going to backend directly. But this is limited on one user alone, and even that just until the browser wipes the storage.

Vinu Prasad

unread,
Oct 20, 2017, 5:01:48 AM10/20/17
to ang...@googlegroups.com
Thank You @Zlatko Duric , thanks for the valuable information


On Fri, Oct 20, 2017 at 2:02 PM, Zlatko Đurić <zlad...@gmail.com> wrote:
Not with angular alone. What you can do is pick up the changes on button click, and send those changes (or the whole new JSON) to a server that can write to files. So if your backend server is something like nginx, apache or "ng serve", you can't write that change. But if you have a Node.js, PHP, Java or something like that, you can overwrite the data.

Alternatively if this is a learning project, you might want to save (with angular) to localStorage of the browser. And on load, first check if there's data in localStorage before going to backend directly. But this is limited on one user alone, and even that just until the browser wipes the storage.

--
You received this message because you are subscribed to a topic in the Google Groups "Angular and AngularJS discussion" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/Qa3Xr95g24I/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+unsubscribe@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.



--
Vinu Prasad
 
Reply all
Reply to author
Forward
0 new messages