I am facing some problem.I need to assign the dynamic value to attribute using Angular.js . I am explaining my code below.

<div ng-repeat="mul in mulImage">
  <a ng-href="attchImage{{$index}}" data-spzoom data-spzoom-width="400" data-spzoom-height="400"></a>
</div>

Here i am trying to assign some link to the anchor tag in controller side. I am explaining my code below.

$scope.onLInkSelect = function(index) {
   atchVar='attchImage'+ index;
   $scope[atchVar]="http://localhost/test/abc.jpg";
}

Here index parameter is containing the value 0,1,2,3,4.... .Here i can not get the result as per expected.Please help me to resolve this issue.

share|improve this question
    
The contents in ng-href is not interpolated the way you seem to be assuming. Consider the following: <a ng-href="http://example.com/{{link}}">some text</a> (only the link part gets interpolated. ) Also since you are already iterating through an array, why not use that? i.e: ng-href="{{mul.link}}" – ippi 2 days ago
    
Since the code doesn't work, it is had to tell what it is meant to do. Right now it displays nothing. What do you want it to show to the user? How do you want the user to intereact with it? – georgeawg 2 days ago
$scope.arr = ['link1', 'link2', ...]

<div ng-repeat="a in arr">
  <a ng-href="{{a}}">link: {{a}}</a>
</div>

<a ng-href="{{arr[1]}}"></a>
<a ng-href="{{arr[1] + '/smth'}}"></a>

etc.

share|improve this answer
    
I could not understand your answer. – satya 2 days ago
    
No need in making variables a1, a2, a3... Make array with variables – Petr Averyanov 2 days ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.