Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot create property 'type' on string - radio button filters

If I define radio button filters in Angular like so:

<input type="radio" ng-model="filter.type" value="rose"  class="type-filter"> Rose<br>
<input type="radio" ng-model="filter.type" value="tomato"  class="type-filter"> Tomato<br>

And the ng-repeat to show the data is:

<div ng-repeat="node in allnodesFiltered | filter:{ plantArray: filter.type}" class="row product-item">
{{node.title}}

The filtering works perfectly. BUT, if I try to use ng-repeat in the filter like this:

<div ng-repeat="plant in plantFilters">
    <input type="radio" ng-model="filter.type" ng-value="filter"  class="type-filter"> Grass
          {{plant}}
    </div> 

I get the error:

TypeError: Cannot create property 'type' on string 'rose'
at fn.assign (eval at <anonymous>

Here is an example of an item in the json array:

title: "Euismod Lucidus Oppeto Probo",
body: "Abico adipiscing facilisi nunc singularis sudo. Antehabeo humo     melior neo obruo ulciscor voco. Aliquam commoveo ea mauris nutus os saepius zelus. Brevitas dolus uxor. Ad cogo decet nobis nutus obruo olim turpis venio virtus. Damnum dignissim lobortis meus mos plaga. Eros iriure loquor macto natu paulatim vel. Consequat humo jus nulla. Abico conventio ibidem si tum typicus uxor volutpat. Diam nutus uxor ymo. Abluo caecus imputo loquor lucidus macto nibh obruo usitas.",
Path: "public://product-images/imagefield_THXgQg.jpg",
productType: "Compost, Weedkiller",
plant: "Rose, Tomato"
like image 946
user3365957 Avatar asked Oct 24 '25 09:10

user3365957


1 Answers

Error itself is saying that you are trying to create a property on a string.In your case ng-repeat will work as you want if array is a "array of JSON object" (not json text). When you prepare your array for ng-repeat, you are pushing json object into array not json text.

var jsonObject = JSON.parse(text);
like image 168
Akhilesh Jaiswal Avatar answered Oct 27 '25 05:10

Akhilesh Jaiswal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!