Mst137 Mst137 - 4 months ago 21
PHP Question

AngularJS: Creating drop-down list without scope variable?

Just wondering if theres a way of creating a drop down list without using scope. For example:

Currently in my javascript file i declare $scope.readWrite = ['R','W'] and then use the following to create a drop down list with it.

<div class="form-group">
<label class="col-sm-3 control-label">Read/Write:</label>
<div class="col-sm-3">
<select class="form-control"
ng-options="item for item in readWrite"
ng-model="singleRegister.RW"
ng-change="modbusChange(modbusDetailsEdit)">
</select>
</div>
</div>


Is there any way of manipulating ng-options so that I can add the items in the list there, for example (know this isnt correct but gets my point across) : ... ng-options=["R","W"] ...

Im having problems with the scope variable in my existing code so was wanting to try something like this as a quick fix.

Answer

You can do this:

    <select class="form-control"
        ng-options="item for item in ['R','W']"
        ng-model="singleRegister.RW"
        ng-change="modbusChange(modbusDetailsEdit)">
    </select>