It is not possible for AngularJS to retrieve values using ng-model when ng-repeat is being used

Is there a way to capture dynamically generated data using ng-model (data created with ng-repeat) so that I can send it as an object to Firebase, my flat database? Currently, the ng-model is only retrieving empty strings as values. Any ideas for a solution?

/////////// Controller below

// Bookmark object
$scope.bookmark = {
url: "",
illnessName: "",
symptom: ""
};

// Save illness card to bookmarks
$scope.saveToBookmarks = ($bookmark) => {
console.log($bookmark);

if ($scope.bookmark.illnessName === ""){
alert("Hey, quit that NAME!");
return;
}
if ($scope.bookmark.symptom === ""){
alert("Hey, quit that SYMPTOM!");
return;
}
if ($scope.bookmark.url === ""){
alert("Hey, quit that URL!");
return;
}


BookmarksFactory.addUserBookmark({
url: $scope.bookmark.url,
illnessName: $scope.bookmark.illnessName,
symptom: $scope.bookmark.symptom
});
console.log("$scope.bookmark.url :",  $scope.bookmark.url);
};


/////// Factory below
"use strict";

app.factory("BookmarksFactory", function(FBCreds, $q, $http) {

var addUserBookmark = (newBookmark) =>{
console.log("Factory is working!");
return $q( (resolve, reject) => {
$http.post(`${FBCreds.databaseURL}/bookmarks.json`,
JSON.stringify(newBookmark))
.then( (FBObj) => {
resolve(FBObj);
})
.catch( (error) => {
reject(error);
});
});
};

return {
addUserBookmark
};

});
<!-- This will be search results populate -->
<div class="search-results" >
<div class="row">
<div class="col-lg-4 text-center search-card box" ng-repeat="illness in illnesses | filter: searchText.search">
<!-- Insert search results here -->
<div class="inner ">
<div class="card">
<button type="button" class="close close-card" aria-label="Close" ng-click="removeCard($event)">
  <span class="close-card-x" aria-hidden="true">&times;</span>
</button>
<img class="card-img-top" src="{{illness.url}}" alt="Card image cap" ng-model="bookmark.url">
<div class="card-block">
<h4 class="card-title" ng-model="bookmark.illnessName">{{illness.illnessName}}</h4>
<p class="card-text" ng-model="bookmark.symptom">{{illness.symptom}}</p>
<button class="btn btn-primary" ng-click="saveToBookmarks(bookmark)">Save</button>
<a href="#!/edit-illness/{{illness.id}}"><button class="btn btn-success" ng-click="goToEditPage()">Edit</button></a>
</div>
</div>
</div>
</div>
</div>
</div>

Answer №1

Modify your code snippet to assign an empty object to the $scope.bookmark variable and then use the HTTP service to fetch data from a file called test.php.

$http({
           method:'POST',
           url:'test.php',
           data : $.param($scope.bookmark), 
           headers : { 'Content-Type': 'application/x-www-form-urlencoded' }
                }).then(success)
function success(){
////

}

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

I am experiencing issues with the pop-up feature in AngularJS

index.html html ng-app="myapp"> <head> <title>kanna</title> <meta charset="UTF-8"> <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.js"></script> <script src="//angular-ui.github.io/boo ...

Print out the data on the webpage that was sent via AJAX

I am currently working on a project where I need to create a web page that takes a number as input and searches for its corresponding name in the database. The challenge is to display the name on the page without reloading it. However, the problem is tha ...

Error: Cannot iterate over Redux props map as it is not a function

I've encountered an issue while trying to render out a Redux state by mapping through an array of objects. Despite receiving the props successfully, I keep getting an error stating that 'map is not a function'. It seems like the mapping func ...

Is it possible to establish a CSS minimum width that is relative to a different element?

Is it possible to set the min-width of a submenu in CSS to be equal to that of the corresponding link in a navigation menu? I am using LESS for my styling. <ul> <li> <a href="">Item FooBarBaz</a> <ul class="submenu"&g ...

How to utilize dot notation in HTML to iterate through nested JSON in AngularJS?

I'm struggling with displaying nested objects loaded from a JSON file in Angular. I've seen examples of using dot notations in HTML to access nested data, but I'm new to Angular and can't seem to get it right. The JSON is valid, but I j ...

Having trouble adding/removing/toggling an element class within a Vue directive?

A successful demonstration can be found at: https://jsfiddle.net/hxyv40ra However, when attempting to incorporate this code within a Vue directive, the button event triggers and the console indicates that the class is removed, yet there is no visual chang ...

Getting the http response content of a Slim PHP API with Angular JS: A step-by-step guide

My Slim PHP programmed API sends JSON responses in the following format: $response['some-text'] = 'blabla'; $app->response->setStatus(200); $app->response()->headers->set('Content-Type', 'application/json& ...

Automatically switch Twitter Bootstrap tabs without any manual effort

Is there a way to set up the Twitter Bootstrap tabs to cycle through on their own, similar to a carousel? I want each tab to automatically switch to the next one every 10 seconds. Check out this example for reference: If you click on the news stories, yo ...

Emulate clicking a radio button (using PHP and JS)

For the past week, I've been struggling to solve this issue with no luck. I admit that I am new to this area, so I ask for your patience. My current problem involves using TastyIgniter, an online food ordering system. In order to add items to the car ...

Having trouble retrieving the HTML content after deploying my application on Heroku

I encountered an issue with my index.js file in Express Node.js once I deployed the app on Heroku. In production, I'm getting an error that seems to indicate that the server is unable to find my index.html file. *-src ---index.html ---index.js http ...

Multi-Slide AngularJS Carousel

My current setup includes a carousel like so: <div> <carousel id="myC" interval="3000" > <slide ng-repeat="order in orders"> <img ng-src="whatever.jpg" style="margin:auto;"> <div ...

Unable to Access Browser Page

After printing out the URL in the console, I encountered an issue while trying to retrieve it using browser.get(). The error message displayed is as follows: Failed: Parameter 'url' must be a string, not object. Failed: Parameter 'url&apo ...

Create visual representations using a JSON structure that includes timestamps for various locations

I need to create a JavaScript graph based on a JSON dataset containing locations and timestamps. The data is structured like an array, and my goal is to visualize the time spent at each location with a comprehensive graph. ...

Utilizing Javascript for altering HTML elements

It seems this issue is quite puzzling and I believe another perspective could be beneficial in identifying the problem. Despite my efforts, I am unable to understand why the "Energy Calculator" does not return a value when submitted, whereas the "Battery C ...

Learn how to effectively manage an element within an HTML-5 document using Protractor

I am new to Protractor and my task involves automating third-party tools. I encountered an issue where I couldn't locate a specific web element that changes its state and pulls data from another application when clicked, causing its class value to cha ...

Transforming Poloniex API Callback JSON into a compatible format for Highcharts.Stockchart

I am currently working on a project that involves retrieving JSON data from Poloniex's public API method (specifically the returnChartData method) to generate a graph using Highchart Stockchart. The graph would display the historical performance of va ...

Creating a custom loading page in Next.js 13: A step-by-step guide

Hello, I am currently working on implementing a loading page for my website to enhance the user experience during a longer loading time. I have created a simple functional component that displays a loading message and imported it into my layout.jsx file in ...

Tips for converting multiple arrays of objects into a single array set

Here is an example of an array: $scope.array1=[[Name:'Madhu'],[Name:'Vijay'],[Name:'Srinu']] I need to convert this array into a different format. I want to pass this array in the columns option of a dx datagrid. So the desi ...

The Loopback Node is throwing an error: 'enum' module not found

I've been searching extensively for a solution, but so far have not been successful. I've already tried the following: 1. npm cache clean --force 2. npm install I've also attempted: 1. Manually removing cache files from C:\U ...

Methods to acquire the 'this' type in TypeScript

class A { method : this = () => this; } My goal is for this to represent the current class when used as a return type, specifically a subclass of A. Therefore, the method should only return values of the same type as the class (not limited to just ...