nAkhmedov
nAkhmedov

Reputation: 3592

angularJS manage one of the input value depends on another`s value

I want to manage requirement if either of input has any value second of them has to fill like that in angularJS

enter image description here

Please help me what kind of approaches are the best in angular way!

Here is my code

            <div class="form-group recipe_item" ng-repeat="recipe in pc.recipes">
            <div class="form-group">
                <label class="col-sm-4 control-label">Select Product</label>

                <div class="col-sm-8" ng-controller="ProductCtrl as pc">
                    <select class="form-control" ng-model="recipe.partId"
                            ng-options="item.id as item.name for item in pc.products"
                            >
                        <option value="">-- choose product --</option>
                    </select>
                </div>
            </div>

            <div class="form-group">
                <label id="lbl_qty" class="col-sm-4 control-label">Quantity</label>

                <div class="col-sm-8">
                    <input type="number" class="form-control" ng-model="recipe.qty" {{isValidNumber(recipe.partId)}}/>
                </div>
            </div>
        </div>

and my controller

$scope.isValidNumber = (number) =>
        return number > 0

Upvotes: 1

Views: 528

Answers (1)

Poyraz Yilmaz
Poyraz Yilmaz

Reputation: 5857

you can use ng-required... this is what you need... here is PLUNKER example...

I updated example by adding angularjs form controller and here is form controller documentation for more details...

Upvotes: 2

Related Questions