angular js scope value not updated in another window - angularjs

I have developed one sample page using angular js.
Just i add comments in textbox and submit, I will add the values in scope variable and display the content in same page using ng repeater, It's working fine but if i open the same page in another window, the old results only displayed,Current scope variable not updated any idea?

You cannot retain the scope of your Angular application in another window. The scope is tied only to the window in which the ngApp is initialized.
In order to overcome this, you can use the LocalStorage of your browser.
EDIT: Please refer this
But in your case, you will have to use a DB or such which will need a backend server too. The MEAN stack is a very nice stack to work on with Angular as the front with Expressjs to connect with Nodejs as the backend along with MongoDB

Related

Why does my angular js service gets destroyed after server call?

As per my understanding services in angularjs are "Singleton". Following is my Scenario where I am using angularjs with Asp.net MVC application.
I have created angularjs service and I use it in one of my controller, which is used on one of the HTML view. If I navigate from that page to some other page, Which results in call to Server then in that case my angularjs Service gets reset. Later, When I come back to the same page my service again gets created/initialized. Can someone please explain me the reason?
Most likely you use ngRoute or angular-ui routing for making single page app, when you change pages controller gets reloaded, which forces all the logic in controller to run again hence call your service, If you are on the view which use other controller its expected not to run service from first one. Some code would be nice too.
hope this helps.

Angular within Bootstrap remote tabs

I have a basic angular page, it pulls some records from a database and displays in a table via ng-repeat - this is working fine as a standalone page.
I'm using bootstrap remote tabs https://github.com/thecodeassassin/bootstrap-remote-data and am calling the above page as one of the tabs' content. The angular page is loaded but angular is not initialising though for some reason. Nothing is binding.
I've tried putting the angular scripts both inside / outside of the tab, and also putting ngApp inside of the tab (remote page) and outside of the tab (parent page) and it doesn't make any difference. Is there something I'm missing?
I am not sure what you are trying to do, but I think the problem is that the angular finishes the loop for initializing the content before the pages are loaded inside the tabs.
have you tried to use ng-include to load the content of the tabs dynamically.
also you may need to call for angular apply to re initiate the binding.
another note, if you are trying to use the tabs to load the data asynchronously, you can use regular tabs and let angular handles the loading of the data using ng-include.

how to refresh values while redirecting to other page in angular factory

I have an multipage application in which i am using angular js, i have my angular controller which is simple and uses the logic which is placed under my angular factory js.
The example i have is that on the first page i have inputs which caters my search parameters on click of search button the results are shown on my second page, first time it works fine.
Now i navigate back to my first search page via browser back button and modify the search parameters on click of search button now i am not able to view the search results or rather the new parameters which i have passed are not getting refreshed.
In short when i am redirecting using angular js, the parameters in the angular factory are not set or rather the values are not refreshed after the second redirect.
How can i refresh the values every time i redirect to some other page using angular factory.
The issue got resolved.
used factory for sharing the values between controllers and services for getting values from server side.
the issue i had is that i had not created my factory properly.

AngularJS: how does ng-include with a dynamic scope variable work?

I'm implementing something where the view changes based on the selected value of a select dropdown. I'm doing this using ng-include="mySelectedValue", which is attached to <select ng-model="mySelectedValue" ng-options="..."></select> tags.
Just wondering what happens under the hood, because this is essentially a SPA with no routes that is being loaded inside one of my Rails apps.
When the app gets loaded, does it just load all the views in the browser somehow? I don't get how angular works so magically. Would love to know how views are popping up when there are no server calls.
I assume mySelectedValue is a src.
According to Angular Docs:
By default, the template URL is restricted to the same domain and
protocol as the application document. This is done by calling
$sce.getTrustedResourceUrl on it.
$sce.getTrustedResourceUrl is basically an ajax request to fetch the corresponding template. So your server call is here :)
After that, there goes the $compile for the template, and renders the view.

angular js scope variables lost on redirect from External call

I'm currently developing a application using angularjs, i have a requirement to redirect from html page to external url, and the external url will inturn redirect back to the same page after some manipulation.
On return to the page all variables that's been stored in scope is lost, is there any way to resolve this problem.
Any help on the same is very much appreciated.
Assuming this is just temporary data, you can use the Angular $cookies service in any controller to store the data you want to save. See this example: "http://docs.angularjs.org/api/ngCookies.$cookies" (click the "script.js" tab for controller example).
After reload, initialize the $scope vars with cookie data. See here for more on initializing scopes: http://docs.angularjs.org/guide/dev_guide.mvc.understanding_controller.
I'd be happy to help you live with this - visit https://www.sudonow.com/, choose a tag, and click "Start Session".

Resources