Angular using Templates
HTML
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.min.js"></script>
<body ng-app="app" ng-controller="Feedback">
<sendemail recipient="teacher.email"></sendemail><br/> <br/>
</body>
JavaScript
angular.module('app', []);
// Directives
angular.module('app').controller('Feedback', function($scope, $http, $log){
$scope.teacher = {
name: "Harry Brown",
email: "harryBrown@harryssite.com"
};
});
angular.module('app').directive('sendemail', function(){
return {
restrict: 'E',
template: '<div><a href="" ng-click="sendEmail()">Send Email</a></div>',
scope: {
recipient: "="
},
link: function postLink(scope, element, attrs) {
// debugger; // scope.$parent already knows the value of teacher here
scope.sendEmail = function(){
console.log(attrs.recipient);
//window.open("mailto:" + attrs.recipient);
}
}
};
});