Pass Array<string> to @Prop


#1

I have a component which has a:

@Prop() values: Array<string>;

Passing an array like this:

<fefe-dropdown values="['value1', 'value2']">

Seems to not work. Any Idea?


#2

maybe (not sure)

<fefe-dropdown [values]="['value1', 'value2']">

or

 <fefe-dropdown values="{{['value1', 'value2']}}">

#3

doesn’t seem to work: I found a solution from a guy on slack who helped me:

[Solution]

Matthias Max:

remember talking about this and the solution I think was to JSON.parse the input in case it is a string.
Thats a little downside I believe with custom elements used natively without other frameworks around it.

So I send a string in json format that I later parse to a json object and then use in my component.


#4

weird but good to know

I know it works with an object I thought it would work with an array too

For example my component https://github.com/fluster/web-social-share takes an object as input

<web-social-share ... [share]="myOptions"...

where myOptions is initialized in my ts code like

this.myOptions = {
            config: [{
        ...
 ]};

but cool cool if you found a solution


#5

Is that possible if your component is declared in the index.html?


#6

It should make any difference no?


#7

brackets around your property won’t work, I guess?

[values]


#8

not sure I understand your question, my property is an object not an array so where should I use brackets?