Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

150
Views
Generate dynamic link angular js

Given this array,i want when i click on a demo it will take me to a link if i click another demo it will take me to another link:

angular.module('app', [])
.controller('MainCtrl', function($scope) {
 
$scope.link = function(){
   var demo = $scope.demos.filter(d => d.paragrafo === 'request')
   if(demo){
     $scope.link = 'https://www.google.it'
   }else{
    alert('Hello')
    }
  }
  
  $scope.demos = [ {
    paragrafo: 'request',
    title:'demo1',
    paragrafo2:'dskjdfdjfdfjkdf',
    id: 1
    },
    {
    paragrafo: 'params',
    title:'demo2',
    paragrafo2:'dfhfhfjgfkjghfjkgf',
    id: 2
    },
    {
    paragrafo: 'request',
    title:'demo3',
    paragrafo2:'sjdsdjddfjdf',
    id: 3
    },
    {
    paragrafo: 'params',
    title:'demo4',
    paragrafo2:'sdjkdhdkjfhdjfh',
    id: 4
    },
    ];
})

I tried to do if condition but i don't know how to do

this is my component, where i put my link:

.directive('card', function(){
  var TPL = `<div class="card" style="width: 18rem">
    <div class="card-body">
      <p>{{c.paragrafo}}</p>
      <h4 class="card-title">{{c.title}}</h4>
      <h6 class="card-subtitle mb-2 text-muted">{{c.paragrafo2}}</h6>
      <p class="card-text"></p>
      <a href ng-click="c.link()" class="card-link">something</a>
    </div>
  </div>`
  var directive = {
restrict: 'E',
template: TPL,
scope: {
paragrafo: '@',  
title: '@',
paragrafo2: '@',
link: '&'
},
controller: ctrlFn,
controllerAs: 'c',
bindToController: true
};

now i have an alert, but i would like to generate a different link for each demo

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

the Array filter method returns an array. Just set the link property in each filtered array item:

$scope.link = function(){
   var filteredDemos = $scope.demos.filter(d => d.paragrafo === 'request')
   for(var i=0; i<filteredDemos.length; i++) {
      filteredDemos.link = 'https://www.google.it';
   }
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!