0

I am using yeoman-generator, which I need to pass a array of value to the template file. for example I want to pass a array of text values to the template.

  install() {
      async app() {
         let array = ['abc','cde','efg'];
           this.fs.copyTpl(
            this.templatePath('base','/abc.ts'),
            this.destinationPath('example/abc.ts'),
            {'array':array}
          );         
      } // app 
  }// install 

in the .ts file, i define a variable which received the passed array.

public options =  <%= array %> ;

My expected result is

public options =  ['abc','cde','efg'] ;

however the resulted output is

 public options =  abc,cde,efg ;

how would I resolve this problem ?

user824624
  • 7,077
  • 27
  • 106
  • 183

1 Answers1

0

in the index.js, the array variable is showed as

let array = ['abc','cde','efg'];

then in the template file, if you want to show ['abc','cde','efg'] instead of abc,cde,efg, all you need to code in the template file is

[<%= array.map(value => '${value}').join(',') %>]

user824624
  • 7,077
  • 27
  • 106
  • 183