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 9304069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T23:37:37+00:00 2026-06-18T23:37:37+00:00

What I am trying to do is postpone loading the angular js template for

  • 0

What I am trying to do is postpone loading the angular js template for a directive until I really need it. I might not even need it at all. Is there a way that I can maybe only load the template for a directive if I need it. Would a service be the way to do this? My application already loads a lot of directive templates and I would like to avoid loading too much stuff unless I need it. The exact problem at hand is the loading of a template for a login form. If the user clicks on a button and he/she is not logged in I want to slideOpen (using jQuery) a login form.

  • 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-18T23:37:39+00:00Added an answer on June 18, 2026 at 11:37 pm

    In the vast majority of cases, there is no value to dynamically loading static directive templates. They are so small that it just doesn’t make sense to do it. But, it is possible. However, most of the time, this strategy is used for dynamic templates.

    It requires $http to fetch the template and $compile to wire it into AngularJS.

    app.directive('testDirective', function($http,$compile) {
      return {
        scope: { show: '&' },
        link: function( scope, element, attrs ) {
          var tpl,
              url = 'testDirective.tpl.html';
    
          scope.$watch( 'show()', function (show) {
            if ( show ) {
              showTheDirective();
            }
          });
    
          function showTheDirective () {
            if ( !tpl ) {
              $http.get( url ).then( function ( response ) {
                tpl = $compile( response.data )( scope );
                element.append(tpl);
              });
            }
          }
        }
      };
    });
    

    Here’s a Plunker demonstrating that it works.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to build out an exception if move.UserId does not equal currentUserId then Redirect
Trying to understand what's the correct way of implementing OpenID authentication with Spring Security.
I'm trying to find the position of all needles in a haystack: $haystack =
I was trying to postpone adding controls to my main form, with a goal
How do I told jquerymobile to postpone executing mobileinit until DOM is loaded? I'm
trying to embed SWF into a FLEX project, importing symbols from it, not whole
Trying to debug a plugin in CRM 2011 can be extremely difficult. Not only
Trying to do something really simple, but can't figure out the syntax. I have
I've been plowing through tutorials all day trying to install RMagick, and have gotten
Trying to import a custom UITableViewCell and it keeps giving me a file not

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.