Transferring information to modal without using AngularUI

I'm currently working on an Angular application and facing an issue with passing data from my controller to a modal.

Here is the HTML code on my index page:

<!DOCTYPE html>
<html lang="en" ng-app="myApp">
<head>
...
</head>
<body ng-controller="myCtrl">

<a href="" data-toggle="modal" data-target="#myModal" ng-click="callModal({{mydata.test}})">
click here
</a>

</body>
</html>

This is how I have set up my controller:

var myApp = angular.module('myApp', []);

myApp.controller('JobListCtrl', ['$scope', '$element', '$http', '$log', function ($scope, $element, $http, $log,) {

    $scope.callModal = function(test){
        $scope.test = test;
    }

}]);

Additionally, here's the directive I am using:

myApp.directive('myModal', ['$rootScope', '$log', '$http', function ($rootScope, $log, $http) {
  return {
    restrict: 'E',

    templateUrl: 'modal-tpl',

    replace: true,

    transclude: true,

    link: function (scope) {

    }
  };
}]);

Below is the template for my modal:

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="ModalLabel" aria-hidden="true">
  <div class="modal-content ease">
    <section>
      {{test}}
    </section>
  </div>
  <div class="modal-overlay ease" data-dismiss="modal"></div>
</div>

I am looking for a way to successfully pass the value of mydata.test to the modal without using angularUI templates. Any alternative solutions would be greatly appreciated. Thank you!

Answer №1

Check out this helpful guide on using isolated scope with attributes in AngularJS

AngularJS provides an isolate scope feature with directives,

I hope this information proves useful to you!

Answer №2

Here's a quick tip: When incorporating an angular directive, you can skip the double curly brackets when referencing angular models. Instead of: ng-click="callModal({{mydata.test}}) Try using: ng-click="callModal(mydata.test)

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

ngDraggable does not function properly when the dropzone is larger and includes a scrollbar on the body

Here is a demo showing the issue: The current version 0.1.11 does not support drag and drop functionality. This is how I have implemented the code: <uib-accordion-group is-open="category.open" name="category-{ ...

Ajax updates previous text to new text upon successfully completing the task

I have a question regarding changing text using AJAX after success. I have written this AJAX code which is functioning properly. However, I aim to replace the old text with new text in the .chnged div. For instance: <input type="text" name="text" va ...

What could be causing my post request to function properly in POSTMAN but not in my React application?

Here are my POSTMAN headers along with the settings I used to send my POST. It only started working when I switched the Content-Type to application/json. https://i.stack.imgur.com/Xz2As.png https://i.stack.imgur.com/aJtbD.png This pertains to the server ...

Adding jQuery content to a div that is being created dynamically

Currently implementing a save/load feature using JSON for a diagram that utilizes jsPlumb. While the save functionality is working perfectly, the load functionality is encountering difficulties in replicating the full initial saved state. The issue arises ...

What is the best way to conceal elements that do not have any subsequent elements with a specific class?

Here is the HTML code I have, and I am looking to use jQuery to hide all lsHeader elements that do not have any subsequent elements with the class 'contact'. <div id="B" class="lsHeader">B</div> <div id="contact_1" class="contac ...

Tips on dividing the information in AngularJS

Sample JS code: $scope.data={"0.19", "C:0.13", "C:0.196|D:0.23"} .filter('formatData', function () { return function (input) { if (input.indexOf(":") != -1) { var output = input .split ...

When accessing req.user in code not within a router's get or post method

Is there a way for me to access the data in the User schema outside of a post or get request? I am asking this because I would like to use this information elsewhere. The user schema is defined as follows: const mongoose = require('mongoose'); c ...

Remove text on the canvas without affecting the image

Is there a way to remove text from my canvas element without losing the background image of the canvas? I'm considering saving the Image source and reapplying it to the Canvas Element after using clearRect, but I'm unsure how to execute this sol ...

Tips for patiently waiting for a series of asynchronous calls to successfully complete

I have a scenario where I am dealing with multiple asynchronous calls that are dependent on each other's success. For example: function1 = () => { /*Some required Logic*/ return fetch("myurl") .then((json) => { functi ...

Vue3 - Implementing a seamless communication channel between two child components

Vue 3 has brought about changes in my component structure, as shown below: In this setup, ChildA can communicate with ChildB and requires ChildB to update its state accordingly. In Vue 2, I could send an event from ChildA: this.$root.$emit('new-mess ...

I will receive a 404 error if I try to access a URL without including the hashtag symbol

Is it feasible to display a record by directly inputting the user ID in the URL without using the # symbol? I am currently working on a website where I have a single view page named Login.html. I want to be able to access this page by entering the user&ap ...

Send live information to router-link

I'm struggling to pass a dynamic path to vue-router, but I can't seem to get the syntax right. Here's what I've been attempting: <li v-on:click="$emit('closeDropdown')"><router-link :to="item.route" id="button">{{ ...

Maintain the expanded sub-menu when the mouse leaves the area, but a sub-option has been

Implementing a side menu with parent and child options that dynamically display content in the main div on the right when a child option is selected. The parent options are initially shown upon page load, and the child options appear when the mouse hovers ...

Tips for modifying the font color of placeholders within md-chips?

I'm working on some code that involves an md-autocomplete element. At the moment, I am looking to modify the font color of the chip's placeholder. <md-chips flex class="md-accent" ng-model="vm.job.skills" readonly="vm.isExpi ...

Using the increment operator within a for loop in JavaScript

this code snippet causes an endless loop for (let i = 0; ++i;) { console.log(i) } the one that follows doesn't even run, why is that? for (let i = 0; i++;) { console.log(i) } I want a thorough understanding of this concept ...

Sending a function along with event and additional arguments to a child component as a prop

I've managed to set up a navigation bar, but now I need to add more complexity to it. Specifically, I have certain links that should only be accessible to users with specific permissions. If a user without the necessary permissions tries to access the ...

AngularJS allows us to easily include the route provider templateUrl path in the view div, making

I have the following route provider setup: $routeProvider .when('/', { templateUrl: '/slapppoc/Style Library/TAC/Views/tarification/home.html', controller: 'homeController' /* resolve: { // This f ...

Updating state in React is not possible

I am having trouble updating my state (specifically with setCoords). The API request is returning a 200 status code and the elements I need are present: https://i.stack.imgur.com/a8QzN.png Below is the code I am working with: const App = () => { co ...

retrieve the responseText in an ajax request

I am looking to receive Ajax feedback. var response = $.ajax({ url : 'linkAPI', type : 'get', dataType: 'JSON' }); console.log(response); Only the respo ...

Angular offers a range of search filters for optimizing search results

The system currently has 3 search fields: 1. Name.... 2. Subject.... 3.Price.... Each of these filters works independently - when searching by name, only results matching that name are displayed; similarly for subject and price. However, the challeng ...