angularjs - Cannot $remove in nested controllers with angularfire -
i using angularfire manage online courses , have courses each have many lectures. nested lectures within courses. have factory allows crud operations on courses lectures, can except delete. tell me doing wrong delete? much!
courses factory:
angular.module('rutileapp') .factory('course', function ($firebasearray, $firebaseobject, ref) { var courses = $firebasearray(ref.child('courses')); var course = { all: courses, create: function (course) { return courses.$add(course); }, get: function(courseid) { return $firebaseobject(ref.child('courses').child(courseid)); }, delete: function(course) { return courses.$remove(course); } }; return course; });
lectures factory:
angular.module('rutileapp') .factory('lecture', function ($firebasearray, $firebaseobject, ref) { var lecture = { create: function (courseid, lecture) { return $firebasearray(ref.child('courses').child(courseid) .child('lectures')).$add(lecture); }, get: function(courseid, lectureid) { return $firebaseobject(ref.child('courses') .child(courseid).child('lectures').child(lectureid)); }, fromcourse: function(courseid) { return $firebasearray(ref.child('courses') .child(courseid).child('lectures')); }, delete: function(courseid,lecture) { return $firebasearray(ref.child('courses').child(courseid) .child('lectures')).$remove(lecture); } }; return lecture; });
courses controller:
$scope.deletecourse = function (course) { course.delete(course); };
course controller:
$scope.deletelecture = function (courseid, lecture) { lecture.delete(courseid, lecture); };
courses view:
<table class="table table-striped"> <thead> <tr> <th></th> </tr> </thead> <tbody> <tr ng-repeat="course in courses"> <td> <button class="btn btn-primary" ng-really-click="deletecourse(course)" ng-really-message="are sure?"> delete </button> </td> </tr> </tbody> </table>
course view:
<table class="table table-striped"> <thead> <th></th> </thead> <tbody> <tr ng-repeat="lecture in lectures"> <td> <button class="btn btn-primary" ng-really-click="deletelecture(course.$id, lecture)" ng-really-message="are sure?"> delete </button> </td> </tr> </tbody> </table>
this happens if deletelecture(course.$id, lecture.$id).
try renaming delete remove, delete can reserved keyword in javascript languages.
Comments
Post a Comment