CRUD AngularJS - Update

413 views
Skip to first unread message

Hélio Miranda

unread,
Mar 8, 2013, 5:24:41 AM3/8/13
to ang...@googlegroups.com
Hi

I'm making an application in AngularJS, and I'm doing CRUD information, since all I need to do the update ...

And I have some difficulty ...
Has anyone done something like that can help me?

thank you

Oto Dočkal

unread,
Mar 8, 2013, 5:34:03 AM3/8/13
to ang...@googlegroups.com
Hi,
small example is here, but check also docs http://docs.angularjs.org/api/ngResource.$resource.

This should be sufficient:
    var Item = $resource('url', {}, {
      index: {method:'GET', isArray:true},
      show: {method:'GET'},
      create: {method:'POST'},
      update: {method:'PUT'},
      remove: {method:'DELETE'}
    });
    Item.update({}, successCb, errorCb);


Dne pátek, 8. března 2013 11:24:41 UTC+1 Hélio Miranda napsal(a):

Hélio Miranda

unread,
Mar 8, 2013, 5:41:50 AM3/8/13
to ang...@googlegroups.com
Thanks, but it's not my problem right there ...

It even edit the data ... I'm trying to follow this example:

But I am not able to edit the registry as exexplo in the code ... I am trying is as follows:

someone can give me some help on how to edit only the desired record?
Message has been deleted

Sander Elias

unread,
Mar 8, 2013, 7:03:08 AM3/8/13
to ang...@googlegroups.com
Hi,

I tried to make sense out off your sample. Can you reduce it to the least amount off code you need to demonstrate your problem. I'm seeing some mistakes in the HTML, and also some things seems strange to me in your JS. But that might just me me ;)

regards
Sander Elias

Hélio Miranda

unread,
Mar 8, 2013, 7:18:56 AM3/8/13
to ang...@googlegroups.com
reduce my code ... I am not able to edit the data of a record.
As I said before, I wanted to follow the example I posted above ...

How do I edit only one record? How will I get the data to edit?

The reduced my code:

thank you

Sander Elias

unread,
Mar 8, 2013, 7:32:22 AM3/8/13
to ang...@googlegroups.com
Hi,

Your Plunker is not working at all, the djnago.js is not being loaded. As a result angular stops processing the HTML. If you have a plunker that works, except for the problem you are having, I will take a look again.

Regards
Sander Elias

Sander Elias

unread,
Mar 8, 2013, 7:34:03 AM3/8/13
to ang...@googlegroups.com
Hi again,

Didn't want to sound crude. If I had some more tim and/or experience with plunker, I would have solved this issue myself!

Regards
Sander

Hélio Miranda

unread,
Mar 8, 2013, 7:35:11 AM3/8/13
to ang...@googlegroups.com

Sander Elias

unread,
Mar 8, 2013, 7:41:31 AM3/8/13
to ang...@googlegroups.com
from the console:
Uncaught Error: No module: Django 

Hélio Miranda

unread,
Mar 8, 2013, 7:50:54 AM3/8/13
to ang...@googlegroups.com
in my not giving error.

Please note that I have my code to interact with a rest api

My question really is, how to edit the data I receive?
Just wanted to edit a record for example ... how do I do that as another example?

I if I can do what the other sample does, but I can not editing my data, because I need to identify the id, and those records ...

I made myself clear?

Sander Elias

unread,
Mar 8, 2013, 9:06:02 AM3/8/13
to ang...@googlegroups.com
Hi,

Well, the plunker you provided is not working at all. That's the reason your see the {{ ... }} in the result.
according to my javascript console, the django.js is not loaded at all, and so nothing works.
If you fix this, I can take another look at your code.


Regards
Sander Elias

Brett Grace

unread,
Mar 8, 2013, 5:44:40 PM3/8/13
to ang...@googlegroups.com
This plunk isn't working because you have a typo in the script src which loads your app. Replace

  <script src="./Django.js"></script>

with

  <script src="django.js"></script>

and you will at least be able to bootstrap AngularJS so that you can get to work on your real problem.


Calling these methods invoke an 
ng.$http with the specified http method, destination and parameters. When the data is returned from the server then the object is an instance of the resource class. The actions saveremove anddelete are available on it as methods with the $ prefix. This allows you to easily perform CRUD operations (create, read, update, delete) on server-side data like this:

So that means that when you invoke query() or get(id) on your resource, when you make changes to those models, you can call $save on them to have them automatically posted back up to your service (this assumes, for example, that if you GET /test/api/v1/tweet/23/ then you can update tweet 23 by POSTing the new version).

Also, as a reminder, when you post a plunker which queries a resource from localhost, it may work for you but nobody else can see the result.
Reply all
Reply to author
Forward
0 new messages