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

Retrieve the identifying token for a newly generated entry

I am exploring a function that generates a new movie: createMovie.create({ release_date: releaseNL.release_date, imdb_rating: $scope.movieImdbRating.imdbRating, title: $scope.movieListID.original_title, image: $scope.movieLi ...

Displaying customized local JSON information in a Tabulator Table

I'm trying to incorporate local JSON data into a table using Tabulator. Specifically, I want to display the element obj.File.Name from the JSON. While I can render the data in a regular table, I face issues when trying with Tabulator as the data does ...

The use of a Bootstrap row is leading to incorrect dimensions for FullPageJS

Within the body tag, I have included the following code snippet: <div id="container"> <div class="section profile"> <div class="row"> <div class="col-sm-6"> A </div> ...

HTML dropdown menu to trigger an action with the submitted URL

I need assistance creating a menu of options with corresponding URL actions. Here is the structure I have in mind: <form> <select> <option value="1">1</option> <option value="2">2</option> <option value="3 ...

Generating a compilation using ng-repeat

HTML <html lang="en" ng-app="map" xmlns="http://www.w3.org/1999/xhtml"> <body> <div ng-controller="topbarController as topbarCtrl"> <div ng-repeat="pages in topbarCtrl.topbar"> {{pages.page}} </div> &l ...

Can you show me the method to retrieve the value of client.query in Node JS using PG?

I have been working with node.js to establish a database connection with postgresql. Here is what my dbConfig.js file looks like: var pg = require('pg'); var client = new pg.Client({ host:'myhoost', port:'5432', ...

Unable to save object in JavaScript memory

Currently, I am in the process of implementing a Stack in JavaScript using a LinkedList. However, I encountered an issue when trying to instantiate a Node class. When attempting to create a variable let newNode = new Node(x), I am receiving undefined. I a ...

Exploring Angular 6 with Universal Karma for effective module testing

Issue I have been facing challenges while testing my Angular 6 application with Karma. I am encountering errors such as: Can't bind to 'ngModel' since it isn't a known property of 'mat-select'. Although the import works in ...

What is the process of accessing JSON data transmitted from a Express server in JavaScript?

Working with a node server, I've set up a client-server model, meaning the client connects to "localhost" and express generates a response based on certain logic. While I'm able to send a JSON object through the response, I'm unsure of how t ...

I am currently in the process of verifying email addresses

I attempted to validate multiple email addresses from a txt file and then save the valid emails to another txt file using nodejs. Unfortunately, it did not work as expected. Despite successfully reading the file, all emails were deemed invalid, even though ...

Guide to setting the radio_button checked for the first child element in Rails 4

Currently, I am working with rails4 and have encountered an issue related to a dropdown list. My goal is to automatically select the radio_button of the first child element when a parent item is chosen from the dropdown menu. Essentially, the dropdown cons ...

Unable to extract property from object in context due to its undefined status

Having trouble with the useContext hook in my React app for managing the cart state. Keep getting an error stating that the function I'm trying to destructure is undefined. I'm new to using the context API and have tried various solutions like e ...

Duo and reference loop

I'm trying to learn how to use backreferences in JavaScript. I have an array and want to replace it within a string. Here's what I've attempted so far: var items = ["book", "table"]; var sentence = "The $1 is on the $2"; var newSentence ...

Using JavaScript and PHP to dynamically update a field based on two input values within a row of a table

Currently in the process of developing a dynamic profit margin calculator for a personal project. Overview Data is retrieved from a database table using SQL and PHP After necessary validations, the data is dynamically displayed as rows in an HTML table ...

The dropdown in vue-multiselect automatically closes after the first selection is made, ensuring a smooth user experience. However,

I am experiencing an issue where the dropdown closes after the first selection, despite setting close-on-select="false". However, it works properly after the initial select. You can observe this behavior directly on the homepage at the following link: vue ...

.fetchevery(...).then has no function

I recently upgraded Angular to version 1.6.4. As a result, I made changes to the code by replacing .success and .error with .then However, now I am encountering the following error: An unexpected TypeError occurred: .getAll(...).then is not a function ...

I am attempting to retrieve the initial three results from my MySQL database using Node.js, but I keep encountering an error

Below is the code I am currently using: con.query('SELECT * FROM tables', function(err, results) { if (err) throw err console.log(results[0].rawname) for(var i= 0; i <= 3; i++) { ...

The error message "Unexpected token < in JSON at position 0" is indicating a SyntaxError in the

I am facing an issue with the API on this specific page. Although the API is working fine on other pages, it seems to be encountering a problem here. I'm not sure what's causing the issue. Below is the code snippet: export async function getStati ...

Using Javascript's .replace() method to preserve HTML elements

This is a JavaScript function I wrote function replaceCharacters(text_input){ return text_input .replace(/O/g, 0) .replace(/I/g, 1) .replace(/o/g, 0) .replace(/i/g, 1) .replace(/t/g, 4) .replace(/d/g, 9) ...

Animation failing to be queued properly

Here is a snippet of code that moves a heading icon back and forth when you hover over the heading: jQuery('h1.heading').hover( function(){ $icon = jQuery('.heading-icon', this); if( ! $icon.is(':animated') ){ ...