Sending a dynamic list of arguments to an AngularJS directive

Whenever I'm working on some task behind the scenes, I use a specific directive to disable buttons and prevent double submits. You can view the code for this directive here: http://jsfiddle.net/7nA3S/6/

Now, I am interested in enhancing this directive so that it can accept functions with arguments of any length.

While I understand the traditional Angular approach involves assigning necessary values to other attributes on the element, I am exploring if there is a more efficient way to achieve this. One option I am considering is:


<button my-submit='someFunction' args="arg1, arg2, arg3, ...">No Evals</button>

This would involve breaking up the string of arguments, but I am open to better alternatives that do not feel as clunky.

Answer №1

Here is an example that might work for you: http://jsfiddle.net/7nA3S/7/.

If you utilize ng.$parse, you can assess the function with the given arguments against the specified $scope.

Next, extract the passed arguments from the arguments array within the $scope.myAsyncSubmit function.

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

How to rearrange the chosen options in an AngularJS ui-select multiple menu

Is there a way to automatically rearrange the order of selected items in AngularJS ui-select multiple? Check out this code snippet, with more examples available on ui-select github <ui-select multiple ng-model="ctrl.multipleDemo.colors" theme="bootstr ...

Discover the precise number of columns and rows that make up a circle

Is there a way to display a popup message when clicking on a circle in the array to see the number of rows and columns that circle is from the starting point (1,1)? I'm looking for assistance with implementing this feature. var c = document.getEleme ...

What is the most efficient way to submit a form without reloading the page, all while accounting for the PHP script

I have been assigned the task of working on a loan calculator located at loancalc.000webhostapp.com. While browsing through other pages on the same site, I came across a question about submitting a form without reloading the page. However, this informatio ...

How can I transform Json data into html format?

<script> $(document).ready(function() { $("#getMessage").on("click", function() {    $.getJSON("/json/cats.json", function(json) { var html = ""; // Only change code below this line. json.forEach(function(val){ ...

Eliminate unnecessary words from the sentence

I wrote a sentence but it got split at every space. The data is displayed like this: const escapeRE = new RegExp(/([/\?""])/g); const myDatas = data.map(des => des.Sentence.toLowerCase().replace(escapeRE, '').split(' ')); [ [ ...

What is the best way to utilize .some() in determining if a specific property value is present within an array of objects?

I have an array filled with objects, each representing a individual heading to a movie theater. These objects include properties like Name, Age, and Hobby. If there is at least one person under 18 years old, the variable censor should be set to true. Desp ...

Combining the power of Framework7 with the seamless data-binding capabilities of

Hey there, I'm brand new to using Framework7 and I'm trying my hand at data-binding with AngularJS. Unfortunately, I can't seem to get it working quite right. I'm attempting to bind a name from the controller to my HTML but I must be mi ...

Receiving an absence of string or a null value from a text box

My goal is to test the functionality of an <input> element by entering text into a textbox and then displaying that data in the console. However, I am encountering issues with retrieving and printing the content. Additionally, I am interested in test ...

What are the implications of creating a .Net class within JavaScript code using the Jint engine?

One of the unique features in Jint is the ability to access .Net classes in JS. JS File Code : var write = function (msg) { var log = System.Console.WriteLine; log(msg); }; C# Code Engine jsEngine = new Engine(e=>e.AllowClr()); string scr ...

Guide to creating a hierarchical navigation system with HTML

Is there a way to create a menu tree using just HTML and some scripting, without downloading additional software? I tried searching on Google but all the results require downloads. Can anyone provide guidance or help with this task? Thank you in advance. ...

Passing objects to all components in Vue/Vuex without explicitly specifying them

Currently, I am working on some analytical tasks and one of the key elements that needs to be accessed by multiple child elements is the 'link position'. Here is an example to illustrate this: <Page> <MyComponent linkPosition=&apo ...

Multiple executions can be triggered by ng-checked function

Here is the code snippet from the view : <input type="radio" name="tabset" id="tab2" aria-controls="rauchbier" ng-checked="switch_tabs()"> And in the controller, we have: $scope.switch_tabs = function(){ console.log(notificatio ...

What is the best way to incorporate component-specific CSS styles in React?

This is the layout that I am attempting to replicate (originally from react-boilerplate): component |Footer |style.css |Footer.js In Footer.js, the styles are imported in a very elegant manner like this: import React from 'react'; im ...

Supplier for a module relying on data received from the server

My current component relies on "MAT_DATE_FORMATS", but I am encountering an issue where the "useValue" needs to be retrieved from the server. Is there a way to make the provider asynchronous in this case? export const MY_FORMATS = { parse: { d ...

Executing a function in JavaScript using square brackets

While I was reading through the jQuery source code, I came across this interesting line: jQuery(this)[ state ? "show" : "hide" ](); Is there any particular benefit to using this syntax over the more traditional approach shown below? state ? jQuery(this) ...

Enhancing a Pie Chart Dynamically with Ajax using Highcharts

I need assistance with updating the data for the pie chart when a list item is clicked. The issue arises when using dynamic values from $cid in data.php. For example, user_student.cid = 1 works correctly, but if I use user_student.cid = $cid, it doesn&apos ...

Encountering a 500 server error while attempting to retrieve content from Google Images through the Web Speech API

My current project involves utilizing the Web Speech API to dynamically gather free images from Google. Here's how it works: I extract the search keyword using the Web Speech API in JavaScript. The keyword is then sent to the server (PHP) via an a ...

How to use JavaScript regular expressions to extract the content following the second-to-last occurrence of a back

I currently have a regular expression that looks like this: /^.*[\\\/]/ At the moment, it removes every single backslash from a string. However, now I need to modify it in order to capture everything after the second to last backslash. Fo ...

JavaScript loop that removes the first matching element in an array

My array of Exclusions is structured as shown below: Exclusions: [ID:"233242", Loc:"West", ID:"322234" , Loc:"South"] Within my Object, I have a nested array of objects that resembles: Schools : [ O: [ ID:"233242" ] , 1:[ ID:"233242"] , 2: [ID :"954944" ...

Unlocking the Power of RxJS with Observable Sharing

Let's take a look at a function that contains the code below: private foo() { let obs: Observable<any> = this._http.get<number>('/foo') obs.subscribe(x=> { console.log("foo : " + x) }); this.blah(ob ...