I am facing a challenge with my file (courses.json) as I am trying to figure out how to remove courses by clicking on the 'x' next to the course name. Being new to this, I have been struggling to make it work. While I can successfully read from the file, nothing happens when I click on the 'x'. Any assistance in solving this issue would be greatly appreciated!
Below is the snippet of code I have been working with:
var app = angular.module('myApp', []);
app.controller('courses', function($scope, $http) {
$http.get("courses.json").success(function(data) {
$scope.courses = data.kurser;
});
});
function courses($scope, courses) {
$scope.deleteItem = function (key) {
delete $scope.courses[key];
}
}
Here is the HTML part of the code:
<div ng-app="myApp">
<ul ng-controller="courses">
<li ng-repeat="(key, value) in courses" id="course-{{value.courseId}}">
<a href="#" class="courseIcon">{{value.courseName}}</a> <a ng-click="deleteItem(key)">x</a>
</li>
</ul>
</div>