Is there any way to disable template cache in Angular 2 ?
I'm creating one single page application in Angular2.My App have three page. So i use Route to switch from one page to another.In one of my page i have a submit button.I need to disable it based on values selected by user. My issue is that Once i make it disabled it will remain disabled until i refresh the page.It will not enable when i go back to come to same page. This is because of Template caching . Html page is not reloading once it loaded.
Is there any way to disable cache or reload template ?
Thanks
Issue is fixed now. Caching is occurred due to angular 2 beta.0 version. Now I updated it to beta.13. It's working now.
Please try the following links that address your question:
AngularJS disable partial caching on dev machine
How to clear template cache
Alternatively you can try this code:
...
app.run(function($rootScope, $templateCache) {
$rootScope.$on('$routeChangeStart', function(event, next, current) {
if (typeof(current) !== 'undefined'){
$templateCache.remove(current.templateUrl);
}
});
});
Hope it helps!
Related
I'm migrating my angularJS application with ui-router to angular 4 with #uirouter/angular.
I see different behaviour when it comes to links created not via uiSref directive. In #uirouter/angular they reload entire page. Plunker: https://plnkr.co/edit/bF7c29SU1j83opj53Ulc
What is the best workaround to navigate and not reload page?
Turns out, it is problem with angular 2+ itself: Angular 2 Router, href links and unwanted page refresh
I've wrote small script to fix it: https://gist.github.com/Polvista/b19054c705859cef8e38c70de4cf29f8
I have a website where I am switching from addThis to addToAny for social sharing buttons. The problem is that the share buttons are contained in content that is loaded dynamically with jquery Waypoints infinite scroll feature (which uses Ajax). When the page first loads (so no Ajax called yet) everything works great, but when a user scrolls and more content is added that contain the share buttons, the new buttons don't work in that they don't show the share options on hover or click.
There are supposedly fixes for this if using templates from the likes of Drupal or Wordpress, but my site is not built using any of these templates. This was also a known issue with addThis, and to get around the problem you simply need to add 'addthis.toolbox('.addthis_toolbox')' into the success portion of the ajax call and things would work.
I haven't had any success getting addToAny to work after ajax returns. They have something that looked promising: a2a.init('page'), but that doesn't work. Has anyone had this problem and have any suggestions on how to fix it? Thanks!
If there so many share button on one page you can call this after ajax success:
$(".a2a_dd").each(function() {
a2a.init('page');
});
Or if there only one share button, you can use this after ajax success:
a2a.init('page');
If want to know more details go through this document
According to the AddToAny API (https://www.addtoany.com/buttons/api/), you should use a2a.init_all(); if you are loading a number of new share button sets at once via AJAX.
Using a2a.init('page'); only initializes the last uninitialized buttons instance on the page. That might be fine for you, depending on how many new buttons that you load at a time.
Example: you have a blog site that loads new posts when the user scrolls to the end of the page. If you are only loading one new set of share buttons for the new content, a2a.init('page'); should work. If instead, you are loading a few new posts at a time, that each get their own set of share buttons, you will want to use a2a.init_all();
Hope this helps someone!
I'm working on a website that uses html5's push- and popstate in combination with ajax-calls to create a website that dynamically loads in Wordpress posts and pages, without causing a page refresh.
I've got that working fine, but I would love it if the black Wordpress toolbar/adminbar that shows at the top of the site when you're logged in as an admin, also reflected the change of content. Is there any way at all to make this happen? So that when I go from a post to page, for example, the "edit" link in the admin bar updates.
I don't think it's as easy as I hope it is, and if it can't be worked out I think I'll just disable the adminbar on the front-end. But it could be that I'm missing something.
Thanks in advance!
I'm working on this myself. I'm gonna build an ajax action and jquery function to do this. I will post here when it's done. For NOW i've instructed my users to just refresh to get the edit link. if you're using HTML5 history then you're on the permalink you want anyways. refresh and let the server regenerate the bar. not perfect but not terrible.
another option is to put edit post links in your template.
I noticed something interesting while testing the client side validation on a website that used jquery document.ready event.
If I loaded the login page with js disabled its noscript tag redirects the user to a different page informing that the js support wasn't enabled on the browser.
If I loaded the login page with js enabled, and then proceed to disable it, the code attached on its document.ready event was still running and validated perfectly the empty inputs in its login and password fields.
Since I didn't see the page requesting to the server to perform such validation I wonder if its correct to assume that the fact that js was initially enabled was enough for the document.ready to run and attach the code permanently no matter how I toggle the js support afterwards? or Maybe I missed something?.
Thanks for the insight you all can give me.
"Disable javascript" would actually be closer to reality if called "Disable js from now on". Everything that was executed before disabling, well, was executed. Everything that would have happened after the disabling (such as timeouts, intervals, etc), is no longer executed.
Browsers still run JS on currently opened pages even after you disable JS in your settings. Any new pages loaded while JS is disabled will have their scripts disabled.
It's like the browser only checks that setting only on page load:
Load page -> is scipts on? -> yes -> run //changing it anywhere after
-> no -> do not run //does not affect it's status
In the past I have developed large extjs single page applications. Many users get frustrated for not being able to use the Back or Fwd buttons or reload the page.I would also like to warn the user if they navigate away from a page without completing a work flow, and enable users to directly access particular views.
For the next application, I am thinking of using the Codeigniter php MVC framework. It is possible to something similar to this example. I am stucked thinking about the navigation. If I load the ExtJs for each view, that is a significant slowdown.
How best to approach this?
Have a look at the Ext.History class (Ext.util.History on Ext4). With it you can register listeners for changes to the hash:
Ext.History.on('change', function( token ) {
console.log('token changed to: ', token);
});
The Ext.History singleton includes forward() and back() methods for triggering navigation from within the client-side code.
By having only the hash part of the URL change the browser stays on the same page, thus eliminating the need to reload the Ext library.
How this would integrate with your PHP framework I cannot say. I am not familiar with CodeIgniter and your example link goes to a dead page.
Also, do note a caveat with History in that under Ext3 at least it may give you issues with newer browsers. If this is the case an alternative is to code your own History-like solution using the 'hashchange' browser event as illustrated in this answer.