我刚开始。我想要解决这个问题但我做不到。看看,到处重新搜索。我认为自己有义务提问。我已经阅读了有关该主题的所有主题,但我不知道如何解决我的问题。我希望你能帮助我,尝试一切。
我正在使用ionic3 - node.js 8.7:
Slide7Page.html
<ion-list>
<ion-item-sliding *ngFor="let todo of todos | async">
<ion-item>
{{ todo.text }}
</ion-item>
<ion-item-options side="right">
<button ion-button color="danger" (click)="removeTodo(todo._id)">
<ion-icon name="trash"></ion-icon>
Delete
</button>
</ion-item-sliding>
</ion-list>`
Slide7.ts
export class Slide7Page {
todos: Observable <any>;
constructor(public navCtrl: NavController, public navParams: NavParams, public todoService: TodoServiceProvider, public alertCtrl: AlertController, public toastCtrl: ToastController) {
this.loadTodos();
}
loadTodos() {
this.todos = this.todoService.getTodos();
}
}
待办事项-service.js
public getTodos() {
return this.http.get (this.apiUrl + 'todos')}
待办事项-routes.js
app.get('/todos', (req, res) => {
Todo.find({}, (err, todos) => {
if (err) {
return res.json({ success: false, message: 'Error while creating Todo', error: err });
}
res.status(200).send({ success: true, result: todos });
});
});
JSON
{
"success": true,
"result": [
{
"_id": "5a2c488afc7dd1069841ead2",
"created_at": "2017-12-09T20:33:14.294Z",
"text": "Mi Primer TODO",
"__v": 0
}
]
}