Wanna Force AngularJS to Reload/Reevaluate Inline Template in Routing-Table

5,588 views
Skip to first unread message

atoka

unread,
May 16, 2013, 12:25:11 PM5/16/13
to ang...@googlegroups.com
Hi All,

i have defined some routes, but they don't work as expected.
I've defined a menu which are linked to my routes defined in my app.
The problem is that AngularJS doesn't reload the inline template once it has loaded it.
I want AngularJS to reload/evaluate my inline templates every time the user clicks an a link referencing my templates.

My route definitions are as follows:
...
$routeProvider.when('/page1', {template : '<my-special-directive></my-special-directive>'});
$routeProvider.when('/page2', {template : '<my-special-other-directive></my-special-other-directive>'});
$routeProvider.when('/page3', {template : '<yet-another-special-directive></yet-another-special-directive>'});
...
The directives are auto-loading some important data from the server and do manipulate the DOM - displaying the data.

The routes are linked to in my HTML-code, i.e.:

MyMenu:
    1. Link to Page1
    2. Link to Page2
    3. Link to Page3

But it doesn't work. They are only loaded if the URL changes.
I've tried to clear the $templateCache after the $afterRouteChange event and other tricks but it doesn't work.

Does anybody have a solution to this problem?
Thank you in advance.

Regards,
atoka

Sander Elias

unread,
May 17, 2013, 3:12:54 AM5/17/13
to ang...@googlegroups.com
Hi Atoka,

This is done the same way in many AngularJS applications, so it should work. Perhaps you can create a jsfiddle or a plunker to show us your problem?

Regards
Sander Elias

atoka

unread,
May 17, 2013, 12:01:31 PM5/17/13
to ang...@googlegroups.com
Thank you very much Sander.
I'd no time to create a Jsfiddle demo. I will try some ideas which came to my mind. I will post the solution when i solve the problem.

atoka

unread,
May 31, 2013, 7:07:42 AM5/31/13
to ang...@googlegroups.com
Hi all,

my problem still remains.
After some testing i see that location/routing related function do nothing when they determine that the URL hasn't changed?

Does anynody has a solution to this problem?

Kind Regards

Rax

unread,
Jun 3, 2013, 4:51:48 PM6/3/13
to ang...@googlegroups.com
Can you specify your HTML code for linking the pages from menu ?
In my app, I use <a href="#" ng-href="{something}">Page Link</a> and works fine without changing location url.

- rax
--
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 angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

atoka

unread,
Jun 5, 2013, 4:44:30 AM6/5/13
to ang...@googlegroups.com, rak...@thetechtime.com
Hi,

my original links were like this: <a href="#/link1">

I solved my problem using a dirty hack: just appending a search parameter to the URL on every click on the link.
I need still a better solution.

$scope.$on('$routeChangeStart', function() {
     $scope.dateMilliSec = new Date().getTime();
});

The links had have to change too:

<a href="#/link1?p={{dateMilliSec}}">

Kind Regars,
Ahmet

jiri.k...@gmail.com

unread,
Aug 1, 2013, 5:55:50 AM8/1/13
to ang...@googlegroups.com, rak...@thetechtime.com
Hi,

if you use $routeProvider then you can check: https://gist.github.com/jirikavi/6129912#file-authroute-js
if disableCache attribute = true, then cached template '/links' is removed and download from server again every time you go to the url.
.when('/links', {
templateUrl: 'Links.html',
menuItem: 'links',
disableCache: true
})

Regards,
Jiri.

Dne středa, 5. června 2013 10:44:30 UTC+2 atoka napsal(a):
Reply all
Reply to author
Forward
0 new messages