Utilizing various controllers to submit forms

I am working on a project that involves submitting data to the newsfeed table. I have created two forms for this purpose - one for the controller of image path and another for the newsfeed content. My goal is to submit both forms with just one click, but they need to be submitted one after the other (not simultaneously).

<form id="form1" ng-submit="Submit();">
</form>

<form id="form2" ng-submit="newsfeed.regNewsfeed(regData);">
</form>

Answer №1

To solve this issue, you can simply implement the following code:

$scope.submitBothForms = function() {
  $scope.Submit().then(function() {
    newsfeed.registerNewsfeed($scope.regData)
  })
}

Answer №2

If both forms are within the same controller, you have the option to structure your code in the following manner:

<div ng-controller="myController">
  <form id="form1" ng-submit="submitBothForms();"></form>

  <form id="form2" ng-submit="submitBothForms();"></form>
</div>

Within your controller, considering that your Submit function should return a promise, you can implement the following logic:

$scope.submitBothForms = function() {
  $scope.Submit().then(function() {
    newsfeed.regNewsfeed($scope.regData)
  })
}

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

Here's a unique version: "A guide on using jQuery to dynamically adjust the background color of table

I need some assistance with changing the background color of td elements based on the th class. Specifically, I want to target all td elements under the bots class in the HTML code provided below. <table border="1" class="CSSTableGenerator" id="myTab ...

issue arising from integrating material-ui components with code in a react javascript application

Struggling with integrating code and material-ui components in react jsx, I encountered an issue. Here's the problematic snippet: const icols = 0; const makeTableRow = ( x, i, formColumns, handleRemove, handleSelect) => <TableRow key ...

Trouble with HTML2PDF.js - download not being initiated

Currently, I am utilizing html2pdf.js in my project by following this tutorial: https://github.com/eKoopmans/html2pdf.js However, I've encountered an issue where despite implementing everything as instructed, the download prompt for the specified div ...

Utilizing vue-i18n for translating the default value of a Vue component's property

Looking for a solution to localize the default value of a component prop using vue-i18n. Here's an example: export default { name: 'ExampleComponent', props: [{ prompt: { required: false, type: String, default: $t(& ...

Utilize Express.js routes to deliver static files in your web application

I am looking to serve a collection of HTML files as static files, but I want the routes to exclude the .html extension. For example, when someone visits example.com/about, I'd like it to display the contents of about.html In my research on serving ...

Using libraries from the vendors.ts file in webpack with single import

My current configuration involves the following code: 'use strict'; const path = require('path'); const webpack = require("webpack"); const ExtractTextPlugin = require("extract-text-webpack-plugin"); const autoprefixer = require(' ...

What is the best way to pass the value from one textfield to another using material UI in a react application?

I'm looking to transfer the content from a text field in a dialog window to another text field that is not embedded. However, instead of transferring the actual text field value, I'm getting an output of "object Object". Can you help me figure ou ...

What is the process for manually assigning a value to a variable in a test within the Jest framework?

app.test.js In my jest file, I have the code snippet below: 'use strict'; const request = require('supertest'); const app = require('./app'); //https://stackoverflow.com/questions/1714786/query-string-encoding-of-a-javascrip ...

How to align an image in the center of a circular flex container

I'm facing an issue in my Angular project where I have the following code snippet: onChange(event: any) { var reader = new FileReader(); reader.onload = (event: any) => { this.url = event.target.result; }; reader.readAsData ...

Tips for returning JSON data using AJAX

When working with native JS, I am familiar with using AJAX to display the output from PHP/mySql that is not Json Encoded in the element "some_id" like this: <script> function addItem(value) { xmlhttp = new XMLHttpRequest(); xmlhttp.onrea ...

Why is my Javascript for-loop returning "null" instead of the expected value?

Having trouble with the function below that is supposed to calculate the average of all elements in array1. Unfortunately, the function keeps returning null as the result. I can't seem to pinpoint the issue. var array1 = [46,73,-18,0,-442,779,5,1400] ...

Quick way to specify type for Observable in Typescript

Exploring Shortcut Declarations When working with TypeScript, I often take a shortcut when declaring object shapes. Instead of creating an interface first and then specifying that the object conforms to that type, I simply do: object: { fizz: boolean, buz ...

Display a field using React and JavaScript depending on the output of an asynchronous function

I'm working on an asynchronous function to query and return a value. Here's an example of what I have in mind: async function verifyProfileFeature(values: any) { const data = await client.query<any>({ query: PROFILE_QUERY, ...

Steps to sending a parameter to an AngularJS $http success callback

In my AngularJS application, I have implemented the following code: $http.get('/plugin/' + key + '/js').success(function (data) { if (data.length > 0) { console.log(data); // Here, I also need to retrieve the val ...

What is the best way to completely clear $rootScope when a user signs out of my application?

In my development work, I frequently find myself using $rootScope and $scope within controllers and services. Despite searching through numerous Stack Overflow answers for a solution to clear all $scope and $rootScope values, such as setting $rootScope t ...

Guide on updating a variable to the following string within an array

Snippet: months = [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October&apos ...

Encountering difficulties in compiling Dynamic HTML with the $compile function

I'm attempting to incorporate dynamic HTML into my code with the following lines: var el = $compile('<a ng-controller=\"tableController\" ng-click=\"open\">...ReadMore</a>')($scope); But I'm encounterin ...

BufferGeometry does not have a defined position attribute

Is there a method to update the buffer geometry in order for an object position in the mesh to be duplicated into it? I have attempted to update the position matrices without success. ...

Ways to activate a function upon validation of an email input type

Within my HTML form, there is an input type="email" field that requires a valid email pattern for acceptance. I am attempting to send an AJAX request to the server to confirm whether the entered email already exists in the database after it has been verif ...

Can you provide some insight into why the init() method is throwing an error?

My project utilizes DynamoDB access through https://www.npmjs.com/package/react-native-dynamodb. I followed the code provided on the website for implementation. The issue I'm facing is that when hovering over my .init() method in WebStorm IDE, it sho ...