0
我從角度1.0獲得了更多答案。但沒有適合Angular 2的答案。我正在使用mysql作爲數據庫。 我想將此表單的輸入傳遞給nodejs服務器。
錯誤, 1文件: '文件:///c%3A/Users/acer/Desktop/Project/charity/src/app/tasks/tasks.components.ts' 嚴重性: '錯誤' 消息:'參數'事件'隱式地具有'任何'類型。' 源: 'TS'
- 文件:「文件:///c%3A/Users/acer/Desktop/Project/charity/src/app/http.services.ts ' 嚴重程度:'錯誤' 消息:'參數'newTask'隱式具有'任何'類型。' 於:'17,11' 源: 'TS'
--task.component.ts--
<div class="container">
<h2 align="center"><u>Registration Form</u></h2>
</div>
<br>
<form class="form-control" #userForm="ngForm" (ngSubmit)="addTask($event)">
<div class="form-group">
<label for="first name">First Name</label>
<input type="text" class="form-control" ngModel name="fname" required>
</div>
<div class="form-group">
<label for="last name">Last Name</label>
<input type="text" class="form-control" ngModel name="lname" required>
</div>
<div class="form-group">
<label for="Age">Age</label>
<input type="text" class="form-control" ngModel name="age" required>
</div>
<div class="form-group">
<label for="Address">Address</label>
<input type="text" class="form-control" ngModel name="address" required>
</div>
<div class="form-group">
<label for="City">City</label>
<input type="text" class="form-control" ngModel name="city" required>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
--http.service.ts--
import { Injectable, Inject } from '@angular/core';
import { Http, Headers, RequestOptions } from '@angular/http';
import 'rxjs/add/operator/map';
@Injectable()
export class TaskService{
constructor(private http:Http){
console.log('Task Service Initialized...');
}
getTasks(){
return this.http.get('http://localhost:3000/app/tasks')
.map(res => res.json());
}
addTask(newTask){
}
}
明白了!但如何在服務器端讀取數據呢? –
是你的服務器端的實現是基於nodejs的?你提到有關從角度組件讀取數據到數據庫?並且,由於您的初始需求問題已得到解決,請使用現在需要的問題說明編輯您的問題。以便其他人可以幫助您解決該問題。謝謝 –