0

I have an array of links:

$scope.links = [{
   URL: ''    
}];

Then I show those links in the view using data-ng-repeat.

How can I do so that when the user click's any of the links under it will show a textbox? If clicked again the textbox will disappear?

So if the html is:

<div data-ng-repeat="link in links">
   <p>
        <a data-ng-href="{{link.URL}}">{{link.URl}}</a>
   <p>
    // when link above is clicked, insert here textbox
</div>
0

2 Answers 2

1

Try the combination of ngClick and ngIf:

<div data-ng-repeat="link in links">
   <p>
      <a data-ng-href="{{link.URL}}"
         data-ng-click="link.$open = !link.$open">{{link.URl}}</a>
      <input type="text" data-ng-if="link.$open" />
   <p>
</div>
Sign up to request clarification or add additional context in comments.

2 Comments

What is the meaning of link.$open I understand that the link is the current item iterated from links but what about .$open?
@DavidDury arbitrary property name, you can call it however you want ( like a variable ). I prefix it with a $ as a convention because angular strips all prefixed $ when sending data with $http
0

you can utilize the fact that ng-repeat creates a scope for each item. using a temporary variable showHelpText, this is how you can achieve it:

<div data-ng-repeat="link in links">
   <p>
        <a data-ng-href="{{link.URL}}" data-ng-click="showHelpText=!showHelpText">{{link.URl}}</a>
   <p>
    // when link above is clicked, insert here textbox
   <input type="text" data-ng-show="showHelpText">
</div>

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.