Can I ask something slightly related here. How do we maintain the user id
if we are posting data to this API via POST. For example joomla might
render the 'ap' instead of a static web ap and the joomla can then pass in
a token which must be related to the same session or the save doesn't
happen. For an API which is very uncoupled unlike the former scenario and
maybe like the one Tim suggests (a POST to an API) how do we protect the
API and make sure the user id isn't faked for example.
Stateless http requests do this normally via a session matching token I
think and it must be resent back exactly the same so it knows it was from
the good source.
Sorry if this is a little out of the way of what Angular is about but I
need to determine if to use this toolset before I get going. Thank you.
On Monday, 5 November 2012 15:08:21 UTC, Tim Culverhouse wrote:
>
> I do the success callback method Pawel refers to above. The server-side
> code is set up to respond to a POST with the newly saved database entry. I
> then push this response into the array.
>
> Example:
>
> $scope.save = function() {
> Account.save($scope.newAccount, function(response){
> $scope.accounts.push(response);
> });
> }
>
>
> On Mon, Nov 5, 2012 at 8:55 AM, <[email protected] <javascript:>> wrote:
>
>> thankyou for your answer!
>> I will keep updating the whole array after a database write/edit as this
>> seems to be a reasonable way of doing things.
>>
>>
>>
>> Il giorno lunedì 5 novembre 2012 15:19:58 UTC+1, Pawel Kozlowski ha
>> scritto:
>>>
>>> Hi!
>>>
>>> I guess that the best practice depends on the application use-cases
>>> really. If you want to have always the latest data after save issuing
>>> the .query() call after save makes sense. If, on the other hand,
>>> people are not interested by updates coming from other sources (other
>>> users of an app) than I would just update local array with a new
>>> record.
>>>
>>> In any case I would update a local array _only after I'm sure that the
>>> DB call succeeded_ (which in case of $resource means doing this is the
>>> success callback). I would advice against updating a local array first
>>> and doing "silent" call to DB as things can get confusing in case in
>>> save failures. Moreover a persistent data store will often generate a
>>> unique key that should be part of the save object.
>>>
>>> Cheers,
>>> Pawel
>>>
>>> On Mon, Nov 5, 2012 at 2:53 PM, <[email protected]> wrote:
>>> > Hi guys,
>>> > I'm wondering what is the best practice about managing an application
>>> that
>>> > does basic CRUD operations on database data.
>>> >
>>> > The problem is how to syncronize the model data with the database
>>> data. For
>>> > example, say I've got a $scope.records array and a button that adds a
>>> new
>>> > element in the array.
>>> >
>>> > Should I:
>>> > 1) first, update the database through a $resource.save() call, and
>>> then
>>> > refresh my $scope.records with a $resource.query(). This causes a
>>> "flash" of
>>> > content on the screen because the array becomes empty and then
>>> repopulated.
>>> > 2) simply update the model pushing a new element in the array, and
>>> then
>>> > silently updating the database.
>>> >
>>> > Is there maybe any advised persistence framework to automate such db
>>> > synchronization?
>>> >
>>> > thanks in advance.
>>> >
>>> > --
>>> > You received this message because you are subscribed to the Google
>>> Groups
>>> > "AngularJS" group.
>>> > To post to this group, send email to [email protected].
>>> > To unsubscribe from this group, send email to
>>> > [email protected].
>>> > Visit this group at http://groups.google.com/group/angular?hl=en.
>>> >
>>> >
>>>
>>>
>>>
>>> --
>>> Question? Send a fiddle
>>> (http://jsfiddle.net/pkozlowski_opensource/Q2NpJ/) or a plunk
>>> (http://plnkr.co/)
>>> Need help with jsFiddle? Check this:
>>> http://pkozlowskios.wordpress.com/2012/08/12/using-jsfiddle-
>>> with-angularjs/
>>>
>>> Looking for UI widget library for AngularJS? Here you go:
>>> http://angular-ui.github.com/
>>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "AngularJS" group.
>> To post to this group, send email to [email protected]<javascript:>
>> .
>> To unsubscribe from this group, send email to
>> [email protected] <javascript:>.
>> Visit this group at http://groups.google.com/group/angular?hl=en.
>>
>>
>>
>
>
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/groups/opt_out.