Last active
August 29, 2015 14:19
-
-
Save aolshevskiy/8cefe55c4973bbfc13fc to your computer and use it in GitHub Desktop.
parse trick
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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