I'm thinking this should be simple but I'm missing something. How can I pass a flowObj
in my ng-repeat
below to my directive? I want to pass it to my directive then, on click, use that FlowObj
, then apply some logic. I tried using the commented code in my directive
scope: {
test:"@"
}
But it seems to screw up my CSS.
HTML:
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div id="center_outer">
<div id="center_inner" ng-controller="CtrlPageFlow">
<div flowclick class="cflow" ng-repeat="flowObj in flows">
{{flowObj.name}}
</div>
</div>
</div>
</body>
</html>
Here is my directive
angular.module('directives', ['opsimut']).directive('flowclick', function() {
return {
/*
scope: {
test:"@" // set the attribute name on the directive's scope
},
*/
link: function(scope, elem, attr) {
elem.bind('click', function(scope) {
debugger;
alert(scope.flowObj);
//scope.name += '!';
//scope.$apply();
});
}
};
});
SOLUTION BASED ON ANSWER:
angular.module('directives', ['opsimut']).
directive('flowclick', function() {
return {
link: function(e, elem, attr) {
// scope is the directive's scope,
// elem is a jquery lite (or jquery full) object for the directive root element.
// attr is a dictionary of attributes on the directive element.
elem.bind('click', function(e1) {
debugger;
alert(e.flowObj);
}, e);
}
};
});