Is my angularjs application development in the correct way? - angularjs

I am new to angular JS. Now I am creating an application using AngularJS + Codeigniter. I understand the basic concepts of AngularJS. I have done the basic operations like Add, View, Update, Delete records from database. Now I have several doubts.
Normally we fetch the database initially into a scope variable. All the listing is done using this JSON data. If we update a record using $http request the changes affect our database. But it does not change the data in the scope. Ideas to solve this
Made a request to the server to update the scope variable.
Just update the scope variable also along with the updating the database.
Which method should I follow?

I suggest you to use the first method. You should use another request to update the scope data. Using this approach the scope data will always be up to date with the data stored in the database. Also you have to think about what will happen if the database raises some error. If you use the second method the scope data will be temporary updated, but after refreshing the page the new changes will be lost, because nothing is stored in the database.

Related

Controller Properties ASP.NET Core

Have 2 pages for one long process. Both in one controller. My problem is:
In first page, using angular - run method that generate some data. Store that data in property in controller. Move to another page, using angular - run another method and that is... my data in property is null. Is there a solution to store data in controller properties in thid situation?
New instance of a controller is created on every request so whatever you save in property of your controller this will be destroyed together with a controller when request is ended. You have to store this data either on client(cookie, local storage) or server side (session, cache, database etc.).
With ASP.Net MVC, you can't store data in a property between 2 actions.
For achieving this, you have to use cache strategy.
Please, see this link.

How to build sets of entity records using Breeze and local storage

I'm trying to create an off-line data collection app, using AngularJS.
I think, adding Breeze.js should help with saving and querying data to and from the browser local storage:
1) present the user with angular data entry form
2) when the "save" button is clicked - create a new Breeze entity and store it locally
3) the next time this form is used - create a second entity, and add/save it as a part of the same collection
I was wandering if anyone have tried to do something similar and could give me some pointers of how this is done.
I think it's viable and these links should help you to get started:
http://www.breezejs.com/documentation/querying-locally
You also might want to check this Angular sample aswell:
http://www.breezejs.com/samples/todo-angular
One caveat you have to have in mind is that Breeze will need to load the model's metadata from somewhere. Typically you hit a Web API asynchronously and get the metadata from there. However, on your particular scenario you should give a look at trying to load your metadata from a script file. Here's an how-to and discussion about it:
http://www.breezejs.com/documentation/load-metadata-script

how to upate the lists from a page in angular.js after adding an item in the database(couchbase) from another page?

We have a problem in updating the data lists on dashboard page after creating a new list in create page. It already saved on the database, but not updating in the views. It updates once i click the refresh button on the browser but this is a one page web app. How can I update the lists on my dashboard page after adding a data from the previous page without refreshing the page? I used couchbase for database.
The problem here is that you are loading the content from your persistent storage, and then it's in angular as-is, and to retrieve any updates you will have to re-fetch it from your persistent storage. Unfortunately, it is not as simple to $watch your back-end.
You have some options here: if you are making your change from within the angular component of the site, then you can just call a function when you are creating a new page which re-fires your db-access code, and refreshes the model.
If you are making changes from outside of angular, then you will need to either use polling to refresh your angular model periodically, or go for a fancier web-socket option, as explained here.
After reading this question and your other question, my guess would be, that you get the old view from couchbase.
Per default couchbase sets the stale parameter to update_after, which results in getting the updated view only after the second access, see the couchbase documentation for more information.
To fix this, it should be sufficient to set stale to false.
If you access couchbase via REST call, adding ?stale=false to the call should do the trick, otherwise add the parameter according to your used SDK specification.

How can I use Backbone.Model.save() if my whole app and data is local?

I'm making a totally local Backbone app, no server-side included, and I provide the app with some initial local data. The data is actually the Collection data which is a json file and stored in a folder called data. So I provide the Collection with a url attribute which is data/datalist.json and use this.collection.fetch() to get the inital data. All works well.
But I want any update happens in View would save changes to the corresponding Model data in this Collection json data file. It seems that this.model.save({name: newName}) doesn't work for me. Every time I refresh the whole page, the app will still show the inital data file. So how should I change the data file when a item in View is updated, deleted or created? Do I need to set a url attribute in Model?
Model.save calls the Backbone.sync method, which by default maps CRUD functions to a REST api. If you want to use something other than REST for save/update/delete, then you need to override Backbone.sync.
There is a local storage plugin that overrides sync on Github, which is endorsed by Backbonejs: Backbone.localStorage
This plugin should persist your data while the app is running. You may need to extend it if you want to write changes to your filesystem (not sure, haven't used it myself). Hopefully this gets you started.

Data conflict resolution in Silverlight with WCF Service

When using Silverlight together with a WCF Services library how do you solve the age old possibility of two different users loading a record, making different changes to that record and then updating. In other words when updating how does the WCF service know that the data it retrieved is the same as the data it fetched before applying an update?
Do you need to check the original loaded values against the values in the database (i.e. recall the original query before updating)?
I was hoping that there would be a more out-of-the-box answer.
Do you mean using EntityFramework? If so, here is the strategy I used :
When retrieving data on the client side you see that the "RowState" property of the entity is gone. What I did is I added the property on the client side using the "partial class" feature. And I manage locally the value of that RowState value.
When the data goes back to the server for update only send what has been modified filtering by the "RowState" property.
On your Update method, call the ApplyCurrentValues() method of the object.
Maybe there is a better solution for that, but that's what I am using on my project; and it works well on my case :)
Good luck

Resources