Issue: [$compile:multidir] Two directives [form, form] are both requesting the 'form' controller on: <form ng-form="">

I encountered an error while working on a form using angularjs.

`Error: [$compile:multidir] Multiple directives [form, form] asking for 'form' controller on:

<div data-ng-controller="shortlistController">
    <ul>
        <li data-ng-repeat="job in jobs">
            <div>{{ job.role }}</div><div>{{ job.salary }}</div><div>{{ job.company }}</div>
        </li>
    </ul>
</div>

<form ng-form>
    <input type="text" ng-model="newRole">
    <input type="text" ng-model="newSalary">
    <input type="text" ng-model="newCompany">
    <input type="text" ng-model="newUrl">
    <button>Submit</button>
</form>

Initially, the form was placed within the data-ng-controller tag, but I removed it to troubleshoot any issues related to the controller.

If more code is needed, feel free to ask. I am utilizing Angular's native routing system.

Answer №1

These examples all point to the form directive, with minor variations in syntax:

<form></form>
<div form></div>
<div x-form></div>
<div data-form></div>

Therefore, using either <div form></div> or simply <form></form> both refer to the same form directive. However, including <form form></form> would be redundant.

The ngForm directive is essentially an alias for the form directive mentioned above, and can be accessed through any of these methods:

<ng-form></ng-form>
<div ng-form></div>
<div x-ng-form></div>
<div data-ng-form></div>

In your case, you used

<form ng-form></form>
, which is equivalent to <form form></form>, hence the error message.

To learn more about different ways to reference directives, visit: http://docs.angularjs.org/guide/directive

Using the <div ng-form></div> format allows for nested forms, unlike the basic <form> tag.

Answer №2

Using either <form> or the ng-form directive is sufficient, as they are automatically interconnected. There is no need to use both simultaneously.

Answer №3

When I decided to name my component form, I ran into the same issue.

angular.module("testApp").component("form", {
   ...
});

Just like @user553086 mentioned in their response, changing the component's name fixed the problem.

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

Discover the process of retrieving an image from the backend with React and Node.js

Hey there! I'm currently working on a Housing blog using ReactJS and NodeJS. One of the tasks I tackled was creating a login controller in NodeJS to send user details, including the image path from the database, to the frontend. The image path is sto ...

For the past 8 hours, my main focus has been on successfully transmitting a basic JSON object containing data from an API from my Express backend to a React component

I have been trying to achieve my initial goal of retrieving data from the API I am using on the backend, inserting that data into my database, and then sending that data through res.json so it can be accessed on the frontend via fetch. Despite all my attem ...

The importance of utilizing an object FormData in Node.js to ensure the proper functioning of multer for file uploads via ajax with jQuery

Currently, I am learning about Node.js and using Multer, AJAX, and jQuery for file uploads. However, I am feeling a bit confused. Let's say I have the following code in an HTML file: <form action="/" method='post' enctype=" ...

Conceal any elements containing specific numbers in their IDs

Looking for assistance, I am attempting to simplify and provide a basic example: <div id="tree_div"> <ul> <li id="tree_li_401">401</li> <li id="tree_li_101">101</li> <li id="tree_li_301">301&l ...

Node.js async.series not functioning properly within Express application - response being triggered prematurely

In my Node.js Express application, I am setting cookies from various sources such as the server, Twitter, and a database. These tasks need to be executed in series to prevent callback complications. I am attempting to utilize Async.js to achieve this, but ...

What is the best way to manage the gradual disappearance of multiple divs belonging to the same class using jQuery?

I need help with a hover effect for 6 divs on a page. Each div has a layer on top that fades out on hover and fades back in on mouseleave. I currently have code for each individual div layer, but it's causing a stack overrun. How can I assign this fun ...

Retrieve all users along with their respective posts, ensuring that each post is also accompanied by its corresponding comments in

In my Laravel project, I have set up Eloquent models for User, Post, and Comment. The relationships are as follows: User model public function posts(){ return $this->hasMany('App\Post'); } public function comments(){ return $t ...

What could be the reason my span is not altering color as I scroll?

Important HTML Knowledge <section class="home" id="home"> <div class="max-width"> <div class="home-content"> <div class="text-1">Hey t ...

Message successfully sent despite Ajax failure

Hello everyone, I'm currently facing an issue while trying to send a message using the form craft plugin. The error message that I am encountering is " 504 (Gateway Time-out)" along with some technical details: send @ jquery.js:4 ajax ...

Comparing Redux Presentation Components with Container Components

As someone new to React development with Redux, I find myself intrigued by the concepts of Presentational Components and Container Components. How can components be classified as either Presentational or Container? What distinguishes one from the other ...

Tips on implementing a script injected through the JS console to update form data in an Angular webpage and ensure that the changes are successfully saved

I am currently working on enhancing an existing electron app integrated with Angular. The main goal is to inject a script once the application is loaded in order to add a hotkey for efficiency. This hotkey should automatically click an edit button, input s ...

Filter ng-repeat using OR condition for property

I'm trying to filter a list based on a model value entered in a text box. For example: var person={}; person.Id=1; person.Name="Test 1"; person.PetName="Rest 1" var persons=[]; persons.push(person); person.Id=2; person.Name="Test ds"; per ...

Mastering the art of utilizing Context API and Provider for optimal functionality

Currently, I am working on implementing a dark mode feature in my project. Despite everything appearing to be set up correctly, it seems like the Context at App is not re-rendering when I use the setTheme function inside the Provider. Can someone help me t ...

What is the process of importing a JSON data file and utilizing it within a React component?

As a beginner in React, I am struggling with the concepts of importing, exporting, and rendering components. I have a fakeData.json file within the same src/components folder as the component I want to render. Let's take a look at the structure: < ...

Can you explain the function of "app.router" in the context of Express.js?

When looking at the default app.js file generated by express.js, I came across the following line: ... app.use(app.router); ... This particular line of code has left me perplexed for a couple of reasons. First, upon consulting the express api documentati ...

Is it possible to center an anchor link in React JS using Webpack, Sass, and Bootstrap 4?

Recently, I started delving into React JS and Webpack but encountered a perplexing issue. My goal is simple - to center an anchor link on the screen. However, despite trying various methods like inspecting the element, removing inherited styles, setting wi ...

Easily targeting elements and their descendants in jquery: What you need to know!

Within a div, there are nested divs that contain tables and other divs. How can I use jquery to select both the parent div and its children? The parent div has the class "AccordionTitle AccordionTitle-selected". I have attempted the following: var klo=$( ...

Testing Vue Component with Cypress revealed that the function getActivePinia was triggered without an active Pinia instance

Below are the code snippets I'm working with: Test.vue <template> <button v-show="store.common == 'hi'" @click="func"> hello world </button> </template> <script setup> import {mainS ...

Modifying a document by ID in Mongoose without altering a specific field

In my code, I have successfully established a new connection using Mongoose and implemented a schema. Retrieving attributes from the collection is also working as intended. However, when attempting to update my collection, I am encountering difficulties. T ...

avoiding the initiation of a new ajax request while a previous one is still in progress

Attempting to create a function that retrieves data from a server on scroll. The function would look something like this... function onscrollend() { $.ajax({ }); } Feeling a bit perplexed about how to verify if the old .ajax() call is still in pr ...