What is the best way to incorporate dynamic data into dynamic HTML in Angular 1?

I am trying to achieve a scenario similar to this:

https://i.sstatic.net/LLTcK.png

After researching, I found out about $compile, $trustAsHtml, and finally directives. However, in $compile and $trustAsHtml, I can only append static templates or plain HTML without using dynamic elements like ui-sref or ng-click. So, I attempted to create a custom directive but it's not working, and I'm struggling to add multiple templates on click.

Here is the controller code snippet:

app.controller('Ctrl', ['$rootScope', '$scope',function ($rootScope, $scope) 
{     
   $rootScope.enableDirective=false;         
   if(userHasOneApp){// checking some at least one app then only do action
   $rootScope.appicon="img_url"; // data which i am passing
   $rootScope.appname="App_name"; // data which i am passing
   $rootScope.enableDirective=true;
}
}]);

And here's the custom directive:

app.directive('headerTemplate', function () {
    return {               
      template:'<a ui-sref="/event" ng-click="editIt()">'
              +'<img src="{{appicon}}"></a>'
                +'<span>{{appname}}</span>',
        scope:{                                
           appname:'=',
           appicon:'='
        }             
      };
    });

The Header view section looks like this:

<div class="headerdiv">
    <ul ng-if="enableDirective">
        <li header-template appicon="appicon">
         </li>                      
    </ul>
</div>

Lastly, in the Main view:

<div class="maindiv">
    <ui-view></ui-view> <!--basically I want to append template here -->
    <button>Add next template</button>
</div>

Can someone help me figure out where I'm going wrong?

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

Tips for defining boundaries for position absolute elements using JavaScript

Fiddle. I am in the process of developing a chat/mail application with a resizable menu similar to the Google Hangouts desktop app. When resizing the brown content pane at a normal speed, you can observe that the boundaries are functioning as intended. My ...

Unable to retrieve asset from templates folder: name.html

I have successfully integrated an Angular application with a Ruby on Rails application. To load Angular templates, I placed them in app/assets/templates/devices/ and referenced them like this: when("/devices", {templateUrl: "assets/devices/select.html", ...

Using defined variables from ngOnInit() in another function: a step-by-step guide

Recently I've started working with angular 5, and I decided to incorporate the jQuery Rate Yo plugin for rating on my angular 5 website. The ratings are being stored in variables named this.amb, this.clean, this.serv, and this.comf, and I can see thes ...

Steps for displaying text with line breaks on a webpage

https://i.sstatic.net/fxhj6.png I am in need of a way to display text with line breaks using this specific script: <script> var app = angular.module('MyApp', []); app.controller('Ctrl', function ($scope) { consol ...

When making an Ajax call, the response is in JSON format when executed locally, but switches to

Whenever I send an ajax request and retrieve data, the response varies depending on where I execute the code. When I test the web page using Visual Studio and inspect the output in developer tools, I see JSON format like {"d":{"__type":"WebService+MyObject ...

What is the most efficient way to include an object in the map function?

Here's an example of a temp array: 10) [{...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}] 0: {name: "alice", address: "b1", v1: 11.972646011733632, ...} 1: {name: "Bob", address: "b2", v1: 11.972646011733632, ...} 2: {name: "Eve", ...

Is selectpicker acting up?

Currently, I am troubleshooting a filter feature on a website that utilizes jQuery with JSON data. Everything was functioning properly until recently when an error started appearing: The selectpicker function is not recognized I would greatly appreciat ...

Is there a way for me to move the dot icon along the dotline?

Here is the code snippet: jsFiddle I have successfully implemented a click event to change the style of selected dots in dotline. Now, my query is : How can I enable dragging functionality for the dot icon within dotline? Your assistance on this matte ...

When ran automatically as a cron job, the JavaScript script fails to establish a connection with MongoDB

As I connect to mongodb (on a Ubuntu machine) from a js script, everything runs smoothly when I execute the command from the command line (node <name of the script>). However, when I try executing the same command from cron, the connection times out: ...

The crossIcon on the MUI alert form won't let me close it

I am facing an issue with my snackBar and alert components from MUI. I am trying to close the alert using a function or by clicking on the crossIcon, but it's not working as expected. I have used code examples from MUI, but still can't figure out ...

Having trouble sending data from AJAX to PHP

My goal is to implement a "load more" feature in my web app that automatically calls a PHP file to load additional products as soon as the page is fully loaded. In order to achieve this, I am using AJAX to call the PHP file: $(document).ready(function() { ...

Leverage Jasmine for testing a jQuery plugin

I'm currently utilizing the angular-minicolors library () within an angular controller: angular.element("myelement").minicolors({ position: 'top left', change: function() { //custom code to run upon color change } }) Wh ...

How to target the last child in Flexbox using CSS order property

Is there a way to correctly detect the last child after rearranging divs using flex order? Even though I have set the order in the CSS, it is still recognizing the last child based on the DOM tree. Since the items are dynamic, we can't rely on nth-chi ...

What are the steps to resolving the issue of "Property does not exist on type 'Object' in Ionic 3"?

After calling the API to fetch data, I encountered the error message "Property sellerDto does not exist on type Object in ionic3". I tried declaring the data as an object, but the same error persists. How can I resolve this issue? /* @Copyright Notic ...

Showing hierarchical objects retrieved from JSON response

I'm still learning React, so bear with me if this is a simple issue. I have some nested data that I want to show in a list format. The data is fetched and displayed below: data: [ { "id": 1, "domain_url": "localhost", "created_on": "2020-05-26" ...

What is the best webpack configuration for an AngularJS 1.x application in webpack 2?

Looking to start a new Angular 1.x app with webpack 2 from scratch. Struggling to find the perfect configuration for webpack.config, specifically for optimal entry and output settings for production (where all code, styles, and templates are minified and ...

Error encountered when injecting Angular module

Currently, I am attempting to develop a sample Angular application with .Net in order to understand how to connect the two technologies. However, I have been encountering an error related to injector::modulerr that I cannot seem to resolve. Despite trying ...

Is there a way to retrieve real-time information from an API by utilizing the HTTP.Get method?

When working with ANGULAR I am faced with the challenge of pulling data from an API using http.get at regular intervals. The API continuously updates minute by minute traffic data, and I need Angular to display these live updates. Currently, my approach ...

Using JavaScript to save coordinates as a 2D Vector Object

Which option is optimal for both memory usage and calculation speed? new Float32Array(2); new Float64Array(2); {x: 0, y: 0}; [0, 0]; It's clear that option 1 uses less memory than option 2, but what about speed? Are calculations faster with 32 bits ...

Employing ng-style for establishing background when the value does not align

Greetings all! I am using ng-repeat to create a list of items within a ul element. Within the json data, there is a specific value that I want to highlight if it does not match a predefined string. Here's what I have so far: ng-style="{'backgro ...