0

I am working on writing a custom directive.

<ng-selectbox select-function="selectitem(codes)" items="codes"></ng-selectbox> 

code.controller("codeCtrl", function($scope) {  
  $scope.selectitem = function(item){
    alert(item);
  };
});

code.directive("ngSelectbox", function(){
  return {
    restrict: "E",
    scope: {
      items: "=",
      selectFunction: "&"
    },
    template:
    "<div>" +
    "<ul ng-repeat='item in items'>" +
    "<li ng-click='selectFunction(item)'>{{item.TYPE}}</li>" +
    "</ul>" +
    "</div>"
  };
});

when the item in ng-repeat was clicked, I would like to pass the clicked item through selectFunction, but it didn't work. :(

I have no idea what parameter should I put in the html select-function.

thank you very much.

kathy
  • 339
  • 6
  • 17

1 Answers1

0

Can you try to change your template to

"<li ng-click='selectFunction({item:item})'>{{item.TYPE}}</li>"

and check whether it works.

Check my really old answer for more context Can an angular directive pass arguments to functions in expressions specified in the directive's attributes?

Community
  • 1
  • 1
Chandermani
  • 42,589
  • 12
  • 85
  • 88