Tips for updating the template URL when a button is clicked

How can I dynamically change the templateUrl from home.html to customer.html when a button is clicked?

first2.directive('mycustomer', function() 
{
    return {
            restrict: "E",
            replace: 'true',
            template: 'home.html',//want to change this customer.html on button click
          }
});

Is it possible to achieve this functionality?

Answer №1

Imagine you have two templates named aaa.html and bbb.html. To dynamically select between them in your directive, you can do the following

app.directive('mycustomer', function(){
  return {
    templateUrl: function(el, attr) {
      return attr.template + '.html';
    }
  }
});

and then use them like this

<div mycustomer template="aaa"></div>
<div mycustomer template="bbb"></div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Transforming a JSON array into variable names and values extracted from nested form data in order to refill a form

Allow me to clarify this situation. I am working with a form that is converted into nested json from grouped form elements like <input type="checkbox" name="faults[slats][]" value="cracked"/> <input type="checkbox" name="faults[slats][]" value=" ...

How can users create on-click buttons to activate zoom in and zoom out features in a Plotly chart?

I am currently working on an Angular application where I need to implement zoom in and zoom out functionality for a Plotly chart. While the default hoverable mode bar provides this feature, it is not suitable for our specific use case. We require user-cr ...

Guide to utilizing PHP $_POST variables in an AJAX $.ajax post request with JavaScript

Alright, so let me break this down for you: So I have a normal PHP page that processes POST requests and acts accordingly. All good so far. But some content on this page takes too long to load from the database, so I decided to dynamically load it af ...

error TS2559: The type 'BookInterface[]' does not share any properties with the type 'BookInterface'

Hello, I am currently working on a project using Angular 7 and encountering the error TS2559: Type 'BookInterface[]' has no properties in common with type 'BookInterface'. Despite making changes to the code, the issue persists. Below is ...

Why is the value not updating in Vue 3 when modifying an object?

I am working on a project that includes 2 components where I have implemented a query-based search filter. PostsList component: <template> <div> <PostFilter @change-filter="setFilters" /> <h3>Active filters< ...

Obtaining the Camera's Position Relative to the Origin in Three.js

The wording of this question might be unclear, but I'm struggling to phrase it concisely. Here's the scenario: there is a perspective camera in the scene along with a mesh. The mesh is positioned away from the origin of the axis. The camera is ...

Encountering the error "Invalid URL. Please provide only absolute URLs" while trying to integrate the Airtable JavaScript library in a Next.js application

I am currently working on a Next JS application that includes a Page called somePage.js. In this page, I am attempting to make an XHR request to the Airtable API from within the getServerSideProps function. The relevant components look like this: pages/so ...

Discover the method for obtaining a WordPress post by its ID using Ajax

I am a beginner in using ajax with Wordpress and I am trying to retrieve posts based on their ID. Currently, I have written this code which successfully fetches data but does not filter it; instead, it displays all post titles in the popup. add_action(&ap ...

Removing White Spaces in a String Using JavaScript Manually

I have created my own algorithm to achieve the same outcome as this function: var string= string.split(' ').join(''); For example, if I input the String: Hello how are you, it should become Hellohowareyou My approach avoids using ...

Issue with Reactive Form - The call signatures of 'FormGroup' are not compatible

I have a function written in TypeScript: // Form summaryAreaForm = new FormGroup ({ summary: new FormControl(null) }) // Function update() { document.getElementById('textDiv').innerHTML = this.summaryAreaForm('summary').value ...

Threejs: Why is my Pointlight failing to illuminate my shapes?

I've been working on creating a scene with triangles in Threejs. While the BufferGeometry has helped me shape the triangles correctly, I'm facing an issue with lighting. I've tried different materials like standard, phong, and lambert, but n ...

What could be causing the issue with the functionality of third-level nested SortableJS drag-and-drop?

I am currently utilizing SortableJS to develop a drag-and-drop form builder that consists of three types/levels of draggable items: Sections, Questions, and Options. Sections can be dragged and reorganized amongst each other, Questions can be moved within ...

Obtain the object literal string with additional decorative strings surrounding it

In my current Typescript code, I have an object literal structured like this: const MyNamesStrings = { a: { b: "hello", c: "bye" } d: { e: "qwerty" } } However, I am looking for a way to wrap these strings with add ...

What is the process for sorting an item based on a specific criteria?

I am working with an object that looks like this: [insert image description here][1] The object on the screen is represented by dataUserProfile.permissions[dataOriginSelect].permissions I am trying to sort this object based on the 'order' para ...

Having trouble displaying the time in the middle square when pressing TouchableOpacity in React Native?

Having trouble pressing the TouchableOpacity button as it's not responding, and even after pressing it, I need to access the time picker to select a specific time to display inside the square view in the center. Any suggestions on how to resolve this ...

Testing the AngularJS controller with Jasmine unit tests

I am currently attempting to conduct unit testing on an AngularJS controller using Jasmine. The syntax of the controller is slightly different from what is typically documented, and as a result, I am encountering the following error: http://errors.angularj ...

Issues with AJAX post request failing due to XMLHttpRequest validation in Django view

I have a basic HTML page that displays multiple similar forms for the user to submit. After submission, the view is supposed to add a row to the database, update the list of forms with new data, and return it to the browser ('/route/complete/' po ...

ESLint guidelines for handling statements with no content

Oops, I made a mistake and ended up with some pretty subpar code. Initially, I meant to write this: let a = 0; ... a = 2; Instead of assigning to a, however, I mistakenly used double equals sign = let a = 0; ... a == 2; I am aware that it is technically ...

Tips for effectively changing Observable data into an Array

I am currently attempting to transform an Observable into an Array in order to loop through the Array in HTML using ngFor. The Typescript code I have now is causing some issues. When I check the testArray Array in the console, it shows up as undefined. it ...

React not displaying wrapped div

I am facing an issue with my render() function where the outer div is not rendering, but the inner ReactComponent is displaying. Here is a snippet of my code: return( <div style={{background: "black"}}> <[ReactComponent]> ...