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

  • Home
  • SEARCH
  • 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 9217047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:33:13+00:00 2026-06-18T02:33:13+00:00

Is it possible to change templateUrl on the fly by passing values in the

  • 0

Is it possible to change templateUrl on the fly by passing values in the directive’s scope?
I want to pass data to controller that will render the page based on the data that passed from the directive

something maybe that looks like that:

<div> 
   <boom data="{{myData}}" />
</div> 

.directive('boom', function {
        return {
            restrict: 'E',
            transclude: true,
            scope: 'isolate',
            locals: { data: 'bind' },
            templateUrl: "myTemplate({{boom}}})" // <- that of course won't work.
        }
    });
  • 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-18T02:33:14+00:00Added an answer on June 18, 2026 at 2:33 am

    It is possible, but when your template to be loaded depends on some scope-data you can’t use the directive’s templateUrl property anymore and you will be obliged to use lower-level API, namely $http and $compile.

    Roughly what you need to do (only possible in the linking function) is to retrieve template’s content using $http (don’t forget to involve $templateCache!) and then compile template’s content “manually”.

    It might sound like it is a lot of work but in practice it is rather straightforward. I would suggest having a look at the ngInclude directive sources where this pattern is used.

    Here is a skeleton of such a directive:

    app.directive('boom', function($http, $templateCache, $compile, $parse) {
            return {
                restrict: 'E',
                link: function(scope , iElement, iAttrs) {                            
                  var boom = $parse(iAttrs.data)(scope);
                  $http.get('myTemplate'+boom, {cache: $templateCache}).success(function(tplContent){
                    iElement.replaceWith($compile(tplContent)(scope));                
                  });              
                } 
            }
        });
    

    assuming that it would be used as <boom data='name'></boom>. Working plunk here: http://plnkr.co/edit/TunwvhPPS6MdiJxpNBg8?p=preview

    Please note that I’ve changed attributes evaluation from {{name}} to attributes parsing since probably a template should be determined only once, at the beginning.

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

Sidebar

Related Questions

I want to make a single event that will capture every change in the
Is it possible to change SQL in a z/OS mainframe COBOL application so that
Is it possible to change the default collation based on a column? i want
Hi is possible to change the cells that contain specific value to another without
Is it possible to change tab/focus order in an HTML table so that it
Is it possible to change what goes into <c-g> ’s output? Specifically, I want
Possible Duplicate: Change repo name in github I got some github repos that i
Possible Duplicate: Change color of sibling elements on hover using CSS Basically i want
consulting the Facebook documentation on: http://developers.facebook.com/docs/reference/api/page/#tabs I saw that is possible change the tab
Is it possible to change the serialization format of DateTime. Basically i want this

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.