Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

I'm building a MEAN stack app for tracking courses, grades, and assignments. I'm trying to generate delete buttons for courses in my index view. All the expressions render correctly except for course._id in the following table. It is referred to within an ng-click value, so is not braced.

<tbody>
        <tr ng-repeat="course in courseData">
            <td>{{course.name}}</td>
            <td>{{course.courseNum}}</td>
            <td>{{course.students.length}}</td>
            <td>
                <ul ng-repeat="comment in course.comments">
                    <li>{{comment}}</li>
                </ul>
            </td>
            <td>
                <button type="button" class="btn btn-danger" ng-click="remove(course._id)">Delete</button>
            </td>
        </tr>
    </tbody>

The remove function is very straightforward. It sends a delete call to the API and renders the index state again.

$scope.remove = function (courseId) {
    $http.delete("/api/courses/" + courseId);
    $state.go('courseState');
};

It seems like I'm probably missing something simple. Course._id will render outside the ng-click with the curly braces, but the braces can't be used in the ng-click attribute.

Most of the solutions I've found were all about creating directives, but getting that value inside the ng-click attribute should be as simple as just passing course._id as the argument.

share|improve this question
1  
What are you actually trying to accomplish? Rendering the course._id? You aren't displaying it in your markdown anywhere. Putting it in the ng-click attribute isn't going to render it. – sma Apr 11 at 23:44
    
Look at the ng-click attribute of the button. I want the course._id to be passed to the remove() function as a parameter. It can't be put in {{}} because angular will throw errors when trying to parse. According to the Angular docs, the correct way to do it inside the ng-click's value is to just use the property => remove(course._id) – natep Apr 11 at 23:49
    
OK, I was confused by your use of the word 'render' here. What you're actually trying to do is interpolate the value of course._id and pass it to your click handler. In your remove function, what is the value of 'courseId'? – sma Apr 11 at 23:50
    
When the button is available on the front-end, the value of ng-click is remove(course._id). When the buttons are pressed, nothing happens. I would think even if the $http.delete failed, the $state.go would be hit. – natep Apr 12 at 0:18
    
Did you try to change - in HTML: ng-click="remove(course)" and in JS: $scope.remove = function (course) {$http.delete("/api/courses/" + course._id); - that's basically the same as your's but you may can see what;s the real problem is – shershen Apr 12 at 8:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.