Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8776669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:06:43+00:00 2026-06-13T19:06:43+00:00

I am trying to create a directive that would load a template. The template

  • 0

I am trying to create a directive that would load a template. The template will then be cached so the second time you click on the element it would not try to load it but instead get recently loaded value from $templateCache.

I am noticing that in case of the cache hit I don’t get any response from $http.get() method.

<html ng-app="website">
<body ng-controller="MyController">
    <a href='#' ng-click="load()">Click Event</a>
    <a href='#' click-load>Click Directive</a>

</body>
</html>​

angular.module('website', []).directive('clickLoad', function($q, $http, $templateCache) {
    return function(scope, element, attrs) {
        function loadData() {
            $http.get('http://fiddle.jshell.net', {
                cache: $templateCache
            }).then(function(result) {
                alert('loaded ' + result.data.length + " bytes");
            });

        }
        element.bind('click', loadData);
    };
});


function MyController($scope, $http, $templateCache) {
    $scope.load = function() {
        $http.get('http://fiddle.jshell.net', {
            cache: $templateCache
        }).then(function(result) {
            alert('loaded ' + result.data.length + " bytes");
        });
    }
}

I’ve created a fiddle simulating my scenario:

http://jsfiddle.net/3ea64/

Note that you can click Click Event link as many times as you want, however “Click Directive” link only works once if you clicked it first, it doesn’t work at all if you click “Click Event” link first.

Any ideas are greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T19:06:44+00:00Added an answer on June 13, 2026 at 7:06 pm

    I’ve played a bit around and used caching of AngularJS (describes here: http://docs.angularjs.org/api/ng.$http)

    Here is a live demo: http://jsfiddle.net/4SsgA/

    I’ve basically adjusted the $http syntax and use an ng-click directive instead of registering an event listener inside of the directive (just because I like it more :))

    HTML:

    <html ng-app="website">
    <body ng-controller="MyController">
        <a href='#' ng-click="load()">Click Event</a>
        <a href='#' click-load ng-click="loadData()">Click Directive</a>
    </body>
    </html>​
    

    JS:

    angular.module('website', []).directive('clickLoad', function($q, $http, $templateCache) {
        return function(scope, element, attrs) {
            scope.loadData = function() {
                $http({method: 'GET', url: 'http://fiddle.jshell.net', cache: true}).then(function(result) {
                    alert('loaded ' + result.data.length + " bytes");
                });
            }
        };
    });
    
    
    function MyController($scope, $http, $templateCache) {
        $scope.load = function() {
            $http({method: 'GET', url: 'http://fiddle.jshell.net', cache: true}).then(function(result) {
                alert('loaded ' + result.data.length + " bytes");
            });
        }
    }​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create an application that would run on ubuntu desktops,I want
I'm trying to create a wrapper/handler that will be called on the Apache server
I am trying to create a class say MyStack that would implement a java.util.collections
I'm trying to create a T4 template which inherits from another one that is
I'm trying to create a c# function that would hide all child elements that
I am trying to create a function, that will always total the mx variable,
Just as the title says, I'm trying to create a script that will take
I am trying to create a blog dashboard that will connect to your Analytics
Trying to create Database as follows: USE Master GO IF NOT EXISTS(SELECT [Name] FROM
Could anyone help me out on something that is confusing. I'm trying to create

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.