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

191
Views
Pass method child parent angular js

I have this function:

$scope.link = function (){
      return [{
        value: 'https://www.google.it',
        text: 'go to details'
        }
      ]
    }

i want pass this function in parent controller to the child, i tried to do this:

.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 class="card-link">{{c.link()}}</a>
    </div>
  </div>`
  var directive = {
restrict: 'E',
template: TPL,
scope: {
paragrafo: '@',  
title: '@',
paragrafo2: '@',
link: '&'
},
controller: ctrlFn,
controllerAs: 'c',
bindToController: true
};



return directive;

function ctrlFn(){



}
})

and in index.html:

<body ng-app="app" ng-cloak>
    <div ng-controller="MainCtrl">
      <div class="container">
        <div class="row">
          <div class="col" ng-repeat="demo in demos">
            <card title="{{demo.title}}"
                  paragrafo="{{demo.paragrafo}}"
                  paragrafo2="{{demo.paragrafo2}}"
                  link="link()"
                  ></card>
          </div>
        </div>
      </div>
    </div>
  </body>

But the body of the function returns to me, how can i fix this? I want to see the link text "go to details" and when I click on it it takes me to the google page

about 4 years ago · Juan Pablo Isaza
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!