如何将 angular 2 $scope 变量传递到 Node.js 服务器
how to pass angular 2 $scope variables into the Node.js server
我从 angular 1.0 得到了更多答案。但是 Angular 没有合适的答案 2. 我正在为数据库使用 mysql。
我想将此表单的输入传递给 nodejs 服务器。
错误是,
1. 文件:'file:///c%3A/Users/acer/Desktop/Project/charity/src/app/tasks/tasks.components.ts'
严重性:'Error'
消息:“参数 'event' 隐式具有 'any' 类型。”
来源:'ts'
- 文件:'file:///c%3A/Users/acer/Desktop/Project/charity/src/app/http.services.ts'
严重性:'Error'
消息:“参数 'newTask' 隐式具有 'any' 类型。”
在:'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){
}
}
改变
addTask(newTask){}
到
addTask(newTask:any){}
因为你想明确定义类型
我从 angular 1.0 得到了更多答案。但是 Angular 没有合适的答案 2. 我正在为数据库使用 mysql。 我想将此表单的输入传递给 nodejs 服务器。
错误是, 1. 文件:'file:///c%3A/Users/acer/Desktop/Project/charity/src/app/tasks/tasks.components.ts' 严重性:'Error' 消息:“参数 'event' 隐式具有 'any' 类型。” 来源:'ts'
- 文件:'file:///c%3A/Users/acer/Desktop/Project/charity/src/app/http.services.ts' 严重性:'Error' 消息:“参数 'newTask' 隐式具有 'any' 类型。” 在:'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){
}
}
改变
addTask(newTask){}
到
addTask(newTask:any){}
因为你想明确定义类型