我剛剛開始研究節點和角度,我無法將JSON數據傳遞給我的角度組件,並在點擊屏幕上將其呈現在屏幕上一個按鈕。感謝您的幫助。如何將JSON數據從節點發送到角4
這是我要傳遞的JSON數據
{
Customer_ID: 1507843123970,
Bank_Account_Number: 7885236985412589,
Bank_Name: "Some Bank",
Bank_Address1: "Some Address",
Bank_Address2: null,
Account_Holder_Name: "Some Name",
Account_Type: "Savings",
Transaction_Limit: 5000
}
我的服務文件看起來像這樣
@Injectable()
export class ServerService {
constructor(private http: Http) {}
getServer() {
return this.http.get('http://localhost:3000/addFunds')
.map(
(response: Response) => {
const data = response.json();
return data;
}
);
}
}
而且打字稿文件看起來像這樣
export class AddFundComponent implements OnInit {
@ViewChild('addFundForm') addFundForm: NgForm;
showHidden = false;
showBankDetail = false;
showSubmit = true;
servers: Observable<any>;
constructor(private serverService: ServerService) { }
ngOnInit() {
this.servers = this.serverService.getServer();
}
onGet() {
this.serverService.getServer().subscribe(
(data) => {
// const data = response.json();
console.log(data);
},
(error) => console.log(error)
);
}
}
你爲什麼要在內部映射器中創建const?你可以返回response.json() –
好..我回來的數據分配給response.json() – chirag