我想使用laravel和angular插入,但是插入后我想显示NEWtask,但是不幸的是我不能。
你好,我想插入使用laravel和angular,但是插入后我想显示NEWtask,但是不幸的是我不能。
task-form.componet.html
<form (submit)="Add($event)">
<div class="form-group">
<label for="task">Entre Task Title : </label>
<input type="text" name="title" id="task" class="form-control" placeholder="entre title" [(ngModel)]="title">
</div>
<button class="btn btn-danger">add task</button>
</form>
类Task.ts
export class Task{
id:string;
title:string;
status:boolean;
date:Date;
constructor(title){
this.id="no";
this.title=title;
this.status=true;
this.date=new Date();
}
}
task-form.component.ts
import { Component, OnInit } from '@angular/core';
import { TaskService } from '../../../service/task.service';
@Component({
selector: 'app-task-form',
templateUrl: './task-form.component.html',
styleUrls: ['./task-form.component.css']
})
export class TaskFormComponent implements OnInit {
title:string;
constructor(private ts:TaskService) { }
ngOnInit() {
}
add(e){
e.preventDefault();
//console.log(this.title);
this.ts.addTask(this.title);
}
}
task.service.ts
import { Injectable } from '@angular/core';
import { Task } from '../Task';
@Injectable({
providedIn: 'root'
})
export class TaskService {
constructor() { }
addTask(title){
const newTask=new Task(title);
console.log(newTask);
}
}