Monday, 15 February 2010

javascript - How to add selected attribute to ng-repeated dropdown form? -


I have a form that creates multiple widgets based on some JSN data. There is a select dropdown in the part of that form, and some items have different options by default.

i.e.:

  object 1 {tag: "products"}  

select dropdown in ng-repeating widget < / P>

  & lt; Select class = "btn-success form-control" & gt; & Lt; Option value = "companies" & gt; Companies & lt; / Options & gt; & Lt; Option value = "news" & gt; News & lt; / Options & gt; & Lt; Option value = "People" & gt; People & lt; / Options & gt; & Lt; Option value = "product" & gt; Product & lt; / Options & gt; & Lt; / Select & gt;  

^ If this was object 1 , then I would need alternatives to get the product to get the selected attribute.

What I have tried so far has not worked, but you can see my thinking:

HTML

  Ng-repeat = "stuff in things" ... ... & lt; Select class = "btn-success form-control" & gt; & Lt; Option value = "companies" & gt; Companies & lt; / Options & gt; & Lt; Option ng-if = "widget.selectedTag (stuff.tag)" value = "news" & gt; News & lt; / Options & gt; & Lt; Option value = "People" & gt; People & lt; / Options & gt; & Lt; Option value = "product" & gt; Product & lt; / Options & gt; & Lt; / Select & gt;  

Controller

  this.selectedTag = function (s) {console.log (s); If (s = 'news') {return 'selected'; }}  

How can you go about this?

Answer here:

  & lt; Option ng-selected = "{{operator.value == filterCondition.operator}}" ng-repeat = "operator in operator" value = "{{operator.}}" & Gt;  

Then in my case:

  & lt; Option value = "product" ng-selected = "{{stuff.tag == 'products'}}" & gt; Products & lt; / Options & gt;  

No comments:

Post a Comment