Skip to content

Instantly share code, notes, and snippets.

@aolshevskiy
Last active August 29, 2015 14:19
Show Gist options
  • Save aolshevskiy/8cefe55c4973bbfc13fc to your computer and use it in GitHub Desktop.
Save aolshevskiy/8cefe55c4973bbfc13fc to your computer and use it in GitHub Desktop.
parse trick
testCtrl.$inject = ['$scope'];
function testCtrl($scope) {
$scope.foo = function() {
console.log(arguments);
}
}
testDirective.$inject = ['$parse'];
function testDirective($parse) {
var directive = {
restrict: 'E',
link: link,
scope: true
};
function link(scope, element, attrs) {
function someCallback(locals) {
return $parse(attrs.someCallback)(scope, locals);
}
element.click(function(){
scope.$apply(function(){
someCallback({element: 'bar', bar: 'baz'});
});
})
}
return directive;
}
<test-directive some-callback="foo(foo, bar)" ng-controller="testCtrl">Click me!</test-directive>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment