inputName未被放置在getData调用中

时间:2019-01-09 15:22:39

标签: json typescript http ionic-framework ionic3

inputName不会转到getData调用。当我注释掉this.inputName可以正常工作的getdata调用时,我可以看到它。我试图从放置在inputName中的URL获取json。我知道json部分不正确,但希望有帮助。谢谢!

home.ts

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import {Validators, FormBuilder, FormGroup } from '@angular/forms';
import {HttpClient,HttpHeaders} from '@angular/common/http'
import { Observable } from 'rxjs/Observable';
import $ from 'jquery'


@Component({ 
   selector: 'page-home',
   templateUrl: 'home.html'
})

export class HomePage {

private storymap : FormGroup;

  result:any= [];
  data: Observable<any>;
  public  inputName: any;

  constructor(public navCtrl: NavController, public http:HttpClient, private formBuilder: FormBuilder) {
   this.storymap = this.formBuilder.group({
    storymapurl: [''],
    title: ['', Validators.required],
    description: [''],
   });
  }


 getData(){
    this.inputName;
    console.log('here', this.inputName)
    this.data = this.http.get('inputName');
    this.http.get('inputName').map(res => res.json()).subscribe(data => {
    this.result = data;
        });
     console.log(this.result)
  });
 }


 logForm(){


   console.log(this.storymap.value)
 }

}

home.html

<ion-header>
  <ion-navbar>
    <ion-title>Home</ion-title>
  </ion-navbar>
</ion-header>

<ion-content padding>
 <form [formGroup]="storymap" (ngSubmit)="logForm()">
    <ion-item>
         <ion-label color="primary">URL</ion-label>
         <ion-input type="text" placeholder="Storymap URL" formControlName="storymapurl" [(ngModel)]="inputName"></ion-input>
    </ion-item>
    <ion-item>
       <button ion-button (click) = "getData()">Get Data</button>
       <ion-row>Body:{{result.body}}</ion-row>
    </ion-item>
    <ion-item>
     <ion-label>storymap</ion-label>
     <ion-input type="text" formControlName="title"></ion-input>
    </ion-item>
    <ion-item>
      <ion-label>Description</ion-label>
      <ion-textarea formControlName="description"></ion-textarea>
    </ion-item>
     <button ion-button type="submit" [disabled]="!storymap.valid">Submit</button>
    </form>
  </ion-content>

enter image description here

0 个答案:

没有答案