我是MEAN堆栈开发的初学者并做了Todo应用程序,其中我正在创建任务表,然后使用angularjs将todo存储在该特定任务表中.
最初,我只是检索所有待办事项,而不考虑它属于哪个任务表以及创建todos.现在我想要增强它以仅检索特定任务表的待办事项.由于我动态地想要加载它,我正在使用带有值的routeProvider '/:TaskID',其中TaskID正在改变.因此,如果TaskID存在,我正在使用一个函数,否则检索所有内容.
像这样的东西:
if($routeParams.TaskID) {
var id = $routeParams.TaskID;
Todos.getTodosForId(id)
.success(function(data) {
$scope.loading = false;
$scope.formData = {}; // clear the form so our user is ready to enter another
$scope.todos = data; // assign our new list of todos
});
} else {
// GET=====================================================================
// when landing on the page, get all todos and show them
// use the service to get all the todos
Todos.get()
.success(function(data) {
for(var i = 0; i < data.length; i++) …Run Code Online (Sandbox Code Playgroud)