-1

I am trying to grab dynamically created information with ng-model (info created with ng-repeat). I am doing so in order to send the information in the form of an object to my flat database, Firebase. Unfortunately, the ng-model is only grabbing "" (empty strings) as my values. Any suggestions?

/////////// 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>

1 Answer 1

0

change to $scope.bookmark ={}; and use http to get data file you code , example of me is test.php

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

}

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for the response!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.