Angular (0.10.5): Multiple Directive Arguments

If you need to pass multiple arguments in a directive expression, you can use this nifty trick to make your expression behave more like a function.

by vaiism

HTML

<script src="http://harvesthq.github.com/chosen/chosen/chosen.jquery.js"></script>
<link rel="stylesheet" href="http://harvesthq.github.com/chosen/chosen/chosen.css">
<script type="text/javascript" ng:autobind src="http://code.angularjs.org/0.10.5/angular-0.10.5.js"></script>
<div ng:controller="Testing">
    <a ng:array="20, 3, true, 'hello'">Array</a>
    <a ng:object="foo:'hello', bar:'bye', testing:true">Object</a>
    <p>Click on a link and then check your JS console log</p>
</div>

JavaScript

angular.directive('ng:array', function(expression, compiledElement){
    return function(linkElement) {
        var scope = this, arguments;
        arguments = scope.$eval('[' + expression + ']');
        linkElement.click(function(){
            console.log(arguments);
        });
    };
});
angular.directive('ng:object', function(expression, compiledElement){
    return function(linkElement) {
        var scope = this, arguments;
        arguments = scope.$eval('{' + expression + '}');
        linkElement.click(function(){
            console.log(arguments);
        });
    };
});
function Testing() {
}