2016-07-23 65 views
0

我有我的組件的提示警告類似如下:Ionic2綁定值提示警報

addSurveyObject(){ 

    let prompt = Alert.create({ 
     title: 'Add Survey Object', 
     message: "All the fields are necessary", 
     inputs: [ 
     { 
     name: 'name', 
     placeholder: 'Name' 
     }, 
     { 
     name: 'area', 
     placeholder: 'Area', 
     value: this.area 
     }, 
     ], 
     buttons: [ 
     { 
     text: 'Cancel', 
     handler: data => { 
      console.log('Cancel clicked'); 
     } 
     }, 
     { 
     text: 'Save', 
     handler: data => { 

      this.createSuveyObject(data); 

     } 
     } 
     ] 
    }); 

    this.nav.present(prompt); 
    } 

對於「區域」我想填充它的價值,是一個類級別的變量稱爲this.area其獲得的它就像下面的值:

calcar(shape) { 
    const area = google.maps.geometry.spherical.computeArea(shape.getPath()); 
    document.getElementById("area").innerHTML = "Area =" + area.toFixed(2); 
    this.area = area; 
    console.log(this.area) 
    ... 

    } 
    } 

這不會填充提示警報中的值,只能分配字符串。我如何實現這一目標?

+0

這是'this.area'屬性的*類型*? – sebaferreras

+0

它是任何,但我給它分配一個數值 – Nitish

+0

當你設置'name','placeholder'和'value'屬性時,你是否嘗試過添加'type:'number''? – sebaferreras

回答

1

在評論中的答案工作。我只是修改了一下我的代碼,如下所示:

export class StartPage { 
    private area: any; 
    constructor(){ 
    this.area=null 
    } 

在警報:

{ 
    name: 'size', 
    placeholder: 'Size', 
    type: 'number', 
    value: this.area 
},