Pass expression to a custom directives
Description
The following code shows how to pass expression to a custom directives.
Example
<!doctype html>
<html ng-app="MyApp">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js"></script>
<script>
var app = angular.module("MyApp", []);
<!--from w w w . ja v a2 s . c om-->
app.directive("yourWidgetExpr", function() {
var linkFunction = function(scope, element, attributes) {
scope.text = scope.fn({ count: 5 });
};
return {
restrict: "E",
template: "<p>{{text}}</p>",
link: linkFunction,
scope: {
fn: "&fn"
}
};
});
</script>
</head>
<body>
<your-widget-expr fn="count = count + 1"></your-widget-expr>
</body>
</html>