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.

1 Answer 1

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?

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.