Troubleshooting ng-click not functioning within ng-repeat with database integration in MEAN Stack

//app.js

var blogApp = angular.module('BlogApp', []);  

blogApp.controller('BlogController', function($scope, $http){ 

$scope.createPost = createPost;  
$scope.deletePost = deletePost;  

function init(){
getAllPosts();
}

init();



function getAllPosts(){

$http.get("/api/blogpost").success(function (posts){

$scope.posts = posts; 

});

}


function createPost(post){    

console.log(post);  
$http.post("/api/blogpost", post).success(getAllPosts);  
console.log(postId);
}

function deletePost(postId){
console.log(postId);
$http.delete("/api/blogpost/"+postId).success(getAllPosts);   


}


});
<!DOCTYPE html>
<html lang="en" ng-app="BlogApp">
<head>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
  
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
    <script src="app.js"></script>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>

<div class="container" ng-controller="BlogController">
<h1>Blog</h1>

<input ng-model="post.title" class="form-control" placeholder="title"/>
<textarea ng-model="post.body" class="form-control" placeholder="body"></textarea/>
<button ng-click="createPost(post)" class="btn btn-primary btn-block">Post</button>


<div ng-repeat="post in posts">
<h2>
{{post.title}}
<a ng-click="deletPost(post._id)" class="pull-right"><span class="glyphicon glyphicon-remove"></span></a>
</h2>
<em>{{post.posted}}</em>
<p>
{{post.body}}
</p>
</div>

{{posts}} 

</div>
</body>
</html>

Having issues with my ng-click button not triggering the deletePost() function. Spent hours troubleshooting and still can't figure out why it's not working. No response when clicking the glyphicon or button. Any insights on what I might be missing?

Answer №1

The issue with the functionality is related to a spelling mistake:

ng-click="deletPost(post._id)"

should be corrected to:

ng-click="deletePost(post._id)"

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

Setting up numerous instances of TinyMCE for use

I am having trouble initializing two instances of tinymce on my webpage. Even after following the guidance provided in this particular thread, I am unable to get it working. Could it be possible that I need to introduce a timeout between initializing the ...

Unlocking the potential: passing designated text values with Javascript

In my current React code, I am retrieving the value from cookies like this: initialTrafficSource: Cookies.get("initialTrafficSource") || null, Mapping for API const body = {Source: formValue.initialTrafficSource} Desired Output: utmcsr=(direct)|utmcmd=(n ...

Close any open alerts using Protractor

While using protractor and cucumber, I have encountered an issue where some tests may result in displaying an alert box. In order to handle this, I want to check for the presence of an alert box at the start of each test and close/dismiss it if it exists. ...

The button is converting my text to a string instead of the integer format that I require

Hello everyone, I've been grappling with this button conundrum for the last 45 minutes, and I can't seem to find a solution. I have created three different buttons in my code snippet below. (html) <div class="action"> ...

Conflicting Angular controller names within different modules

I'm facing an issue where two modules (A and B) with controllers of the same name are conflicting when imported into module C. Is there a recommended solution to prevent this conflict, such as using a naming convention like "module.controller" for ea ...

How can I use XPATH to target a div after choosing a nested element?

I had the task of creating a universal identifier to locate a dropdown menu following a label. There are 10 different forms, each with a unique structure but consistent format, which means I cannot rely on specific IDs or names. Instead, my approach was to ...

Whenever the state of a React component is modified, it does not automatically trigger a re

Currently, I am utilizing the React Infinite Scroller library to display a list of posts. Interestingly, my load more results function seems to be triggered three times, resulting in the update occurring thrice (verified through console.log). For renderi ...

A guide on effectively mocking functions in Jest tests with Rollup.js

I am currently in the process of developing a React library called MyLibrary, using Rollup.js version 2.58.3 for bundling and jest for unit testing. Synopsis of the Issue The main challenge I am facing is with mocking a module from my library when using j ...

What is the best way to center an infowindow in Google Maps API V3 when working with a map canvas that has a narrow width?

As an illustration of my point, I have put together a sample page: The issue I am facing is with a narrow map canvas and an infowindow in it. Upon clicking the marker, the map sometimes fails to center properly and the marker along with the infowindow sli ...

Exploring the use of barcodes with node.js

Having some issues with generating a barcode using a barcode module from NPMJS called npm i barcode. I am getting an error message res is not defined even after following the instructions. Can someone please guide me in the right direction? Here is my code ...

How can I align Javascript output vertically in the middle?

I am currently facing an issue with a JavaScript clock displaying in a narrow frame: <!DOCTYPE html> <HTML> <HEAD> <TITLE>Untitled</TITLE> <SCRIPT> function checkTime(i) { if (i < 10) { ...

The combination of Apache mod_proxy and Node Express is capable of efficiently rendering plain text

Currently, I have a webserver running Apache 2.2.12 as the default server bound to port 80. I am embarking on a new project that requires me to proxy one of Apache's bound domains via port 80 to a Node Express Server 4.7 also hosted on the same machi ...

Prevent draggable functionality of jQuery UI on elements with a specific class

I have created a dynamic cart feature where users can drag and drop items into the cart. However, once an item is placed in the cart, it should no longer be draggable (though still visible but faded). I attempted to achieve this by using the following code ...

Angular 2 is throwing an error: Unhandled Promise rejection because it cannot find a provider for AuthService. This error is occurring

My application utilizes an AuthService and an AuthGuard to manage user authentication and route guarding. The AuthService is used in both the AuthGuard and a LoginComponent, while the AuthGuard guards routes using CanActivate. However, upon running the app ...

Adjust the scroll bar to move in the reverse direction

I'm trying to modify the behavior of an overlay div that moves when scrolling. Currently, it works as expected, but I want the scroll bar to move in the opposite direction. For example, when I scroll the content to the right, I want the scroll bar to ...

Implementing an onclick function to execute a search operation

Utilizing PHP, I am dynamically populating a dropdown submenu with rows from a database. If the user wishes to edit a specific record listed in the menu, I want to enable them to do so without requiring any additional clicks. My goal is to accomplish this ...

Error: Angular Directive has an undefined scope

I have a specific issue with my directive, where I am trying to extract data from an xls file and pass it to a button through the scope. The problem arises when I am binding to the element change event in the link function and calling a function to parse ...

Troubleshooting AngularJS form submission with missing data

Is there a way to modify AngularJS to save form data into a database using PHP as the backend? Below is the HTML form code: <form ng-submit="newContactSubmit()"> <label>FirstName<input type="text" name="contact_firstname" required n ...

When attempting to submit information to a database table, I encounter an error in the browser console: "Uncaught (in promise) Error: Request failed with status code 404."

In my React Node project's login page, I am encountering the following issue. Despite thoroughly reviewing my code after each execution, the error persists. My goal is to pass data from the login page into my MySQL database; this marks the initial sta ...

Firebase ref.on('value') will repeatedly trigger, even if no changes have occurred

My current setup involves using an event listener to monitor changes in my real-time database. const [chats, setChats] = useState({}); const ref = db.ref(`users/${sender}/chat/`); ref.on('value', (snapshot) => { const data = snapshot ...