如何声明dynamique变量名离子2

时间:2017-05-26 18:31:56

标签: list angular variables typescript ionic2

我想知道如何用离子2动态声明变量名。 我想用离子列表结果实现一个read more函数,但为了做到这一点,我需要有各自的变量名。

//我的ts文件

import { Component } from '@angular/core';
import { NavController,Platform ,LoadingController, NavParams } from 'ionic-
angular';
import { GardeService } from '../../app/services/Garde.service';



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


export class Home {
//data:any;
public newslist: Array<Object>;
mytext:any;
prewords:any;
textpreview:any;
fulltext:any;



constructor(public data:GardeService) {}

ngOnInit()
{
    this.loadnews();
    this.fulltext = true;
    this.textpreview = false;
}

  public loadnews(){
  this.newslist = [];
  var map: {[key:string]:string} = {};
  this.data.LoadNews().subscribe(
  data => {
  for(let i=0;i<data.length;i++){
        //this.newslist.push(data[i]);
        //console.log("news",data[i].content);
        this.mytext = data[i].content.split(' ');
        this.prewords = this.mytext[0] + " " + this.mytext[1] + " " +           
   this.mytext[2] + " " + this.mytext[3] + " " +
        this.mytext[4] + " " + this.mytext[5] + " " + this.mytext[6] + " " + 
   this.mytext[7] + " " + this.mytext[8] + " " +
        this.mytext[9] + " " + this.mytext[10] + " " + this.mytext[11] + " " 
   + this.mytext[12] + " " + this.mytext[13] + " " +
        this.mytext[14] + " " + this.mytext[15] + " " + this.mytext[16] + "" 
       + this.mytext[17] + " " + this.mytext[18] + " " +
        this.mytext[19] + " " + this.mytext[20];
        //map['fulltext'+i] = true;
        this.textpreview = false;
        this.newslist.push({poster: data[i].poster, title: data[i].title, 
       img:data[i].img, content:data[i].content,
        pre:this.prewords});

        //console.log("les mots descriptifs",this.prewords);
  }
},
err => {
  console.log(err);
},
() => console.log('news loaded')
);
}

public readMore(){
  this.textpreview = true;
  this.fulltext = false;
}
}


// my html file

    ion-col width-100 text-wrap>
        <p style="text-align:justify;" color="dark" ion-text>
          <span ion-text [hidden]="textpreview">{{item.pre}}</span><span 
    ion-text (click)="readMore()">...Lire plus</span>
      <span ion-text [hidden]="fulltext">{{item.content}}</span>
    </p>
  </ion-col>

我希望动态更改this.fulltext和this.textpreview变量名称,以便这样做,因为当我点击阅读更多链接时,所有ion-itens的所有内容都会扩展。我只希望它发生在我点击的地方

0 个答案:

没有答案