0

Here is the directive

module.exports = ()=>{
  return {
    restrict: 'E',
    templateUrl: "/components/event/event.html",
    scope: {index: '@'},
    controller: "eventCtrl"
  };
};

The code for controller

module.exports = ($scope)=>{
  console.log($scope.index);
  $scope.loadDetails = ()=>{
    console.log("hello there");
  }
};

and for template

.event
  h3(ng-bind="index.title")
  p(ng-bind="index.description")
  .price(ng-show="index.is_paid") {{cost}} $
  a.button-primary(ng-click="loadDetails()") Details

The problem is the variables are not being rendered in the template. I tested if it is being passed correctly using console.log and i am getting proper response. Also the function loadDetails() is working properly leading me to believe that there is not problem with setting up the controller. Where exactly am i going wrong ?

7
  • the console log is stamp them as string? Commented Feb 28, 2017 at 12:03
  • cause @ .. don't is for string value? Commented Feb 28, 2017 at 12:03
  • Its json object Commented Feb 28, 2017 at 12:16
  • @federicoscamuzzi okay now i think i am getting somewhere, i can't reference field inside index. I think you are right about the string thing, what should i use instead ? Commented Feb 28, 2017 at 12:17
  • Try to use = insted of @ Commented Feb 28, 2017 at 12:19

1 Answer 1

1

You have to change your scope: {index: '@'}, cause @ mean it is for string ..so try with :

module.exports = ()=>{
  return {
    restrict: 'E',
    templateUrl: "/components/event/event.html",
    scope: {index: '='},
    controller: "eventCtrl"
  };
};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.