0

i have problem using angularjs, because i new.

this is my html code :

<select id="provinsiSelect" ui-select2 ng-model="params.id" style="width: 200px;">
    <option value=""></option>
    <option ng-repeat="v in prov" value="{{v.id}}" title="{{v.text}}"
    ng-selected="v.id == params.id">{{v.text}}</option>
</select>

<select id="kabupatenSelect" disabled ui-select2 ng-model="params2.id" style="width: 200px;">
    <option value=""></option>
    <option ng-repeat="y in kab" value="{{y.id}}" title="{{y.text}}"
    ng-selected="y.id == params.id">{{y.text}}</option>
</select>

as you can see that, there are two select, please help me when first select change, then second select enable from disable.

2 Answers 2

2

Simply use ng-disabled:

<select id="provinsiSelect" ui-select2 ng-model="params.id" style="width: 200px;">
    <option value=""></option>
    <option ng-repeat="v in prov" value="{{v.id}}" title="{{v.text}}"
    ng-selected="v.id == params.id">{{v.text}}</option>
</select>

<select id="kabupatenSelect" ng-disabled="params.id" ui-select2 ng-model="params2.id" style="width: 200px;">
    <option value=""></option>
    <option ng-repeat="y in kab" value="{{y.id}}" title="{{y.text}}"
    ng-selected="y.id == params.id">{{y.text}}</option>
</select>

Assuming you don't have an id of 0, params.id should be truthy once an id has been selected.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you joseph, you code work. but i need otherwise. as you can see that, there are two select, please help me when first select change, then second select enable from disable.
0

With ng-disabled as the previous comment said. You should also add a watch on the first select variable, and just set the params.id to the value you need on change.

$scope.$watch('provinsiSelect', function (newVal) {
    $scope.params.id = true;
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.