Sto pensando che questo dovrebbe essere semplice ma mi manca qualcosa. Come posso passare uno flowObj
nel mio ng-repeat
di seguito alla mia direttiva? Voglio passarlo alla mia direttiva, quindi al momento del clic utilizzare FlowObj
quindi applicare una logica. Ho provato ad usare il codice commentato nella mia direttivaAngularJs passa l'istanza di ogni ng-repeat in HTML alla direttiva
scope: {
test:"@"
}
Ma sembra rovinare il mio 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>
Qui è la mia direttiva
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();
});
}
};
});
soluzione basata su RISPOSTA:
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);
}
};
});