0

I have an input text on my html side,

   <input ng-model="item.valueProperty"
       ng-disabled="item.options.length>0"
       type="text"
       placeholder="List item value"
       class="form-control"
       required>

if item.options array has any item, my textbox value (item.valueProperty) will be set as key But I want to this on html side via ng- directives.

I can not set it on javascript controller. is this possible?

7
  • Can you explain what problem you are facing. Commented Mar 4, 2017 at 19:56
  • setting input value by options lenght. if it has items value of item.valueProperty will be "key" Commented Mar 4, 2017 at 19:59
  • if it has items value of item.valueProperty will be "key" ? Commented Mar 4, 2017 at 20:03
  • item.valueProperty is a model. model value will be set as "key" text. Commented Mar 4, 2017 at 20:04
  • ng-model="item.valueProperty" is correct syntax to bind ng-model. I stilldon't know what issue you are facing. Commented Mar 4, 2017 at 20:06

1 Answer 1

2

I think this is what you wantL

angular.module('test', [])
  .controller('test', function ($scope) {
    $scope.item = {
      valueProperty: 'Test',
      options: [1]
    };
  });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="test" ng-controller="test">
<input ng-model="item.valueProperty"
       ng-disabled="item.options.length > 0 ? item.valueProperty='key' : false"
       type="text"
       placeholder="List item value"
       class="form-control"
       required>
</div>

I just set $scope.item.valueProperty to 'key' if item.options.length > 0 in ng-disabled directive, item.options.length > 0 ? item.valueProperty=123 : falseis a valid expression, so it will work.

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

2 Comments

Yes it is thanks, so I learned to set model values on html side.
Yes, but seems to be a bad practice, try to use controllers. Enjoy it!

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.