简体   繁体   中英

Retrieve angular ng-repeat scope outside ng-repeat

I have a ng-repeat select element, which is formed from the MySQL table, problem is - can't output scope parameter outside of the ng-repeat of the selected option.

What I tried doing:

<select ng-model="rec_name">
     <option value=" ">Select</option>
     <option ng-selected="{{rec_name == item}}"  ng-repeat="item in tasks" value="{{item.name}}">{{item.name}}</option>
</select>
<div>Operator is: {{rec_name}}</div>

Basically, it's almost what I need, but it only shows the value="{{item.name}}" in the Operator div field; which is logically understandable.

Thought, that simply making the equivalence of item and rec_name will allow me to do something like

<div>Operator is: {{rec_name.param}}</div>

Again, what am I trying to do is to output the task.param of currently selected option,formed from tasks, in the isolated from ng-repeat div .

How do I call other item parameters?

Thank you for help.

you can do like this:

<select ng-model="rec_name">
                <option value=" ">Select</option>
                <option ng-selected="{{rec_name == item}}"  ng-repeat="item in tasks" value="{{item.name}}">
<a href="#" ng-click="rec_name == item">
                            {{item.name}}
                        </a>
</option>
</select>
<div>Operator is: {{rec_name}}</div>

Cheers:)

You have to manually handle the click event.

Use the following code

HTML

<select class="form-control" ng-model="selecteditem"
        ng-options="selecteditem as selecteditem.brand for selecteditem in dropdownval">

                </select>
<div>Operator is: {{clicked_rec_name}}</div>


Have the following method in your controller

$scope.getClickedItem=function(item)
{
        $scope.clicked_rec_name=item.rec_name;
}

LIVE DEMO

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM