0

I have an input field which could be enabled or disabled depending on the condition. Its corresponding label has '*' to indicate that the input field is mandatory. Currently the '*' is displayed all the time which should only be displayed when the input field is editable.

<label>Field Label *</label>
<input ng-model="someObject.value" ng-if="!someObject.allowEdit" ng-readonly="true"/>

I am trying to add condition that if the input field is readonly then don't show '*', for that, I am doing something as below but I don't know how to check the input field's readonly property with angularJS.

<label>Field Label 
    <div style="display:inline" ng-show="[if inupt field.readonly == false]">*</div>
</label>
<input ng-model="someObject.value" ng-if="!someObject.allowEdit" ng-readonly="true"/>
1
  • a jsfiddle would be appreciated.. Commented Jun 12, 2014 at 11:25

2 Answers 2

1

Try this:

    <div ng-controller="MyCtrl">
        <div ng-repeat="item in data">
            <label>Field Label 
                <span style="display:inline" ng-show="!item.allowEdit">*</span>
                <span style="display:inline" ng-show="item.allowEdit">&nbsp;</span>
            </label>
            <input ng-model="item.name" ng-hide="item.allowEdit"/>
            <input ng-model="item.name" ng-show="item.allowEdit" ng-readonly="true"/>
        </div>
    </div>

Here is a Fiddle

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

Comments

1

At the end I have come up with this solution which is more succinct.

<label>Field Label {{someObject.allowEdit ? " *" : ""}}</label>

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.