Atlas91
Atlas91

Reputation: 5904

Get value outside ng-repeat angular

I have something like this (based from Show value outside the ng-repeat):

    {{ Brands[?].BrandDetails.Text }} // i want show element selected value
    <li ng-repeat="Brand in Brands">
          <a href="#">
           {{Brand.BrandDetails.Text}}
          </a>
    </li>

Actually it shows only first BrandDetails.Text but if i have 3 < li> attribute doesn't work. It shows always the first result instead the item i selected.. How can i solve?

edit: what i want is that when i click on the item of this kind of menu, it shows me the Brand.BrandDetails.Text of corrispondent item outside the ng-repeat.. So i can use the result from everywhere in my html

Upvotes: 2

Views: 1413

Answers (1)

nada
nada

Reputation: 972

First of all in ng-repeat it's recommended to use ng-src instead of just src.

If you use src you will load "~/Images/{{Brand.BrandDetails.Image}}" as is.

I don't really undestand your question. What you want?


With this {{ Brands[0].BrandDetails.Text }} you're selecting the 1st brand.

With this {{ Brands[1].BrandDetails.Text }} you're selecting the 2nd brand.

etc...


or create a new $scope.var = Brands[X] and then call {{var.BrandDetails.Text}} or whatever

Please show us your expected output HTML

UPDATE:

Reference to your updated post. Use something like that:

{{ Brands[someVar].BrandDetails.Text }}
<li ng-repeat="Brand in Brands" ng-click="someVar = $index">
      <a href="#">
           {{Brand.BrandDetails.Text}}
      </a>
</li>

Upvotes: 1

Related Questions