-1

I have to create an elemental custom directive which will consist of two html elements. first one is radio button group with values yes or no. no is default. if yes is clicked on , and input text field should be displayed. I should be able to keep default for radio and get the value of text field if it is entered.

please help me with any template

learning developer
  • 429
  • 2
  • 6
  • 10
  • you should attempt this on your own first. if you have problems then come back here and post your code to get help. – Ero Jun 22 '17 at 19:50

1 Answers1

1

you can check below plunker for example , its simple directive with shared scope , for reference you can check this link https://docs.angularjs.org/guide/directive and my template is as below

<input type="radio" name="myradio" ng-model="myradio" value="Yes">Yes</input>
<input type="radio" name="myradio" ng-model="myradio" value="No">No</input>
<input type="text" ng-model="mytext" ng-show="myradio==='Yes'"/>

In example , you can access value of enter text from variable "mytext" , you can set default value of radio button by setting value of variable "myradio" to Yes or No , I had set this value to No in controller.

This directive can be improved by making this isolated scope and you can use it multiple times , you can try that on your own.

Please find plunker link below

https://plnkr.co/edit/0ZsNelh2DWUwMSRmvgfa?p=preview

Srinivas ML
  • 732
  • 3
  • 12