Is it advisable for $parsers/$formatters to be executed in a location separate from the link function?

From my understanding, the angular link function serves the purpose of "registering DOM listeners and updating the DOM."

However, upon examining this example:

app.directive('changecase', function () {
  return {
    restrict: 'A',
    require: 'ngModel',
    link: function (scope, element, attrs, ngModel) {

      //format text going to user (model to view)
      ngModel.$formatters.push(function(value) {
        return value.toUpperCase();
      });

      //format text from the user (view to model)
      ngModel.$parsers.push(function(value) {
        return value.toLowerCase();
      });
    }
  }
});

I have come across numerous instances where the link function is utilized to "firewall" undesirable values both into and out of the model.

Question

This action does not involve manipulating the DOM or handling listeners.

It appears rather unconventional to place these "firewalls" within the link function.

Is it indeed the appropriate location for $parsers/$formatters?

Answer â„–1

From what I understand— the link function within angular serves the purpose of "registering DOM listeners as well as updating the DOM."

These guidelines are not set in stone, they are practical considerations. Pre-link and post-link functions provide access to the necessary controller (ngModel).

Therefore, utilizing the link function is the correct approach.

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

Encountering the issue "Unable to set headers once they have been sent" while attempting to store an image and user information in a MongoDB database

I am currently working on a simple application using Node.js, Express, MongoDB, and Angular. The application includes a form where users can input data and upload an image. To handle the image upload functionality, I'm utilizing ng-file-upload. In ord ...

ReactJS: Understanding the Interconnectedness of Components

In my application, I have two main components: Table (which is a child of Tables) and Connection (which is a child of Connections). Both Tables and Connections are children of the App component. The issue I am facing is that the Table component needs to be ...

Accessing a Global Variable within a Node Express Class Module

Within my Node Express application, I defined a variable in app.js like so: let accounts = [checkingAccount, savingAccount] Now, I have a class file named account.js (not a route) and I need to access the accounts array from within it. How can I achieve t ...

ExtJS web displays appear differently when viewed on Chrome's toggle device mode versus a mobile browser

Greetings, I have been working on developing a web application that can be accessed through a mobile browser. Initially, I created the web application and tested it in mobile mode using Chrome's simulation feature. https://i.sstatic.net/aAvVW.jpg H ...

Utilizing Angular Controllers to Access HTML Elements without the Need for jQuery

Within my Controller, I am trying to access an html element that is generated automatically by an external library on the DOM. Unfortunately, importing a directive inside the html is not an option in this case. So, my question is: Is there a way to retrie ...

Tips for updating nested documents in mongoose with Node.js

Hi everyone, I'm facing some challenges with updating a nested document using mongoose. flashcardDeck.updateOne({ _id: deck._id }, { $set: { flashcards[Math.floor(i/2)].side1: newFlashcardsArr[i]}}); I'm encountering errors when trying to specif ...

AngularJS JSON data computation

As I delve into learning angularjs (not 2), one of the challenges I face is calculating the total amount for a customer order. The data I'm working with is structured as follows: var clients = [ { id: 1, jo ...

Submit data via POST method on the modified URL

I need assistance with modifying the data of a URL and making a POST request to it. The URL in question is as follows: http://domanin.com/search-result/?start=06%2F08%2F2017&end=06%2F09%2F2017&room_num_search=1&adult_number=1&children_num= ...

Tips on attaching the main element of a partial view

I have a scenario in my ASP.NET MVC project where I need to render a partial view once in the main view, and then upon clicking the add button, I want to append the entire partial view to the form. However, when I click add, only the child element is added ...

Is there a way to restrict keyboard input on this date picker?

Can you review the following link and let me know which properties or events I should utilize in this scenario? https://codesandbox.io/s/charming-frost-qrvwe?file=/src/App.js ...

In JavaScript, you can verify whether the content or blank space of an element was clicked

Is it possible to determine if the clicked part of an element is text or white space? https://i.sstatic.net/0pFgB.jpg My attempts so far have been unsuccessful: body.addEventListener('contextmenu', (e) => { e.preventDefault(); // Prevent ...

Steps for submitting a form once all inputs have been verified

$('#f_name, #l_name').change(function(){ if($(this).val().length < 2) { $(this).css('border', '1px solid red'); alert('names must be at least 2 symbols'); check ...

Executing WebApi: A Step-by-Step Guide

Hey there! I'm currently diving into the world of WebApi using VS2015. Having some background in MVC4, I'm familiar with concepts like Routing in MVC$. Right now, I'm following a tutorial on the website to display data from a database. pub ...

Passing the Authorization Header for DataSource in GrapeCity's ActiveReportsJSLearn how to pass the

Our UI developer is working with VueJS, and we specifically need guidance on integrating JWT authentication within the ActiveReportsJS report viewer or designer. This is crucial as it's all based on JavaScript. We are currently utilizing JWT's w ...

Updating JQuery function after window is resized

click here Currently, I am using slick-slider to showcase content in 3 columns by utilizing flexbox. The aim is to have the slider activated only on mobile view. This means that when the screen size shrinks down to mobile view, the 3 column flexbox transf ...

Step-by-Step Guide: Exporting a div to a beautifully formatted PDF with NextJs

Currently, I am working on an app project that involves filling out forms and having the information automatically formatted into a div to generate CLP labels. My goal is to be able to export this div in pdf format while also being able to select sizes ran ...

Simulated FileList for Angular 5 App Unit Testing

Imitation FileList In my pursuit of writing a unit test (Angular5), I have encountered the need for a FileList. Despite researching extensively, I have been unable to uncover any clues or solutions. I am starting to question whether this is even feasible ...

Version 1.x of Remix.run encountered issues when attempting to resolve paths containing the "$" symbol during both compilation and runtime, particularly when handling paths with dynamic segments

Attempting to deploy a Remix 1.x app on a Linux machine running Debian 12 (amd64) with Typescript, but encountering issues. The same code builds and runs successfully on a Mac OS Machine (M1). Seeking assistance to resolve the problem that arises during t ...

Can a module factory be invoked from a different JavaScript file?

I have two separate javascript files and I am trying to retrieve one from another. To achieve this, I have created a Module factory as shown below; var module = angular.module('test',[]); module.factory('$result', function() { va ...

A guide on retrieving bytecode from a specific PDF using Angular

Can anyone help me with extracting the bytecode from a selected PDF file to save it in my database? I keep encountering an error stating that my byte is undefined. Could someone please review my code and identify what might be causing this issue? I attemp ...