In my form I have a input tag with name="Customer.Firstname" so when i refer to name value in angularjs its taking only customer as the value and .Firstname is going unidentified. Here is my code:
<label class="label_block" ng-hide="ApplicantDetails.Customer.FirstName.$error.required || ApplicantDetails.Customer.FirstName.$error.pattern">FirstName</label>
<span class="clearable">
<input class="textbox" type="text" name="Customer.FirstName" ng-model="Customer.FirstName" ng-init="Customer.FirstName='@Model.Customer.FirstName'" value="@Model.Customer.FirstName" ng-pattern="/^([a-zA-Z-']{1,30})$/" required="required"/>
</span>
Here am trying to hide the label when the textbox is empty.How can i do that?
In my form I have a input tag with name="Customer.Firstname" so when i refer to name value in angularjs its taking only customer as the value and .Firstname is going unidentified. Here is my code:
<label class="label_block" ng-hide="ApplicantDetails.Customer.FirstName.$error.required || ApplicantDetails.Customer.FirstName.$error.pattern">FirstName</label>
<span class="clearable">
<input class="textbox" type="text" name="Customer.FirstName" ng-model="Customer.FirstName" ng-init="Customer.FirstName='@Model.Customer.FirstName'" value="@Model.Customer.FirstName" ng-pattern="/^([a-zA-Z-']{1,30})$/" required="required"/>
</span>
Here am trying to hide the label when the textbox is empty.How can i do that?
Share Improve this question edited Oct 16, 2013 at 12:21 Halcyon 57.7k10 gold badges92 silver badges130 bronze badges asked Oct 16, 2013 at 12:20 PaRsHPaRsH 1,3205 gold badges29 silver badges59 bronze badges 2- You can give a different name than the ng-model. It could be CustomerFirstName. Or maybe use thé array notation like Form['Customer.FirstName'] – jpmorin Commented Oct 16, 2013 at 12:27
- possible duplicate of JavaScript property access: dot notation vs. brackets? – Stewie Commented Oct 16, 2013 at 12:35
1 Answer
Reset to default 11You can use bracket notation to access keys with dot
<label class="label_block" ng-hide="ApplicantDetails['Customer.FirstName'].$error.required || ApplicantDetails['Customer.FirstName'].$error.pattern">FirstName</label>
Demo: Fiddle
This can be rewritten as
<label class="label_block" ng-show="ApplicantDetails['Customer.FirstName'].$valid">FirstName</label>
Demo: Fiddle