Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Calculator

0

77
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

7 months ago ยท Juan Pablo Isaza
Answer question
Find remote jobs