我认为这应该很简单,但我错过了一些东西。如何将下面的 a 传递给flowObj
我ng-repeat
的指令?我想将它传递给我的指令,然后在点击时使用它FlowObj
,然后应用一些逻辑。我尝试在指令中使用注释代码
scope: {
test:"@"
}
但它似乎搞砸了我的 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>
这是我的指令
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();
});
}
};
});
基于答案的解决方案:
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);
}
};
});