Skip to content

Instantly share code, notes, and snippets.

@ysyun
Created April 14, 2013 12:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ysyun/5382630 to your computer and use it in GitHub Desktop.
Save ysyun/5382630 to your computer and use it in GitHub Desktop.
AngularJS & scope send local property to parent scope
/*
& scope
<div ng-app="phoneApp">
<div ng-controller="AppCtrl">
<div phone dial="callHome(message)"></div>
<div phone dial="callHome(message)"></div>
</div>
</div>
*/
var app = angular.module("phoneApp", []);
app.controller("AppCtrl", function($scope) {
$scope.callHome = function(message) {
alert(message);
}
})
app.directive("phone", function() {
return {
scope: {
dial: "&"
},
template: '<input type="text" ng-model="value">' +
'<div class="button" ng-click="dial({message:value})">Call Home</div> '
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment