• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

145
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 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error