AngularJS Directives talking to Controllers

Egghead.io - 14

by TahmidTanzim

HTML

<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.0/css/bootstrap-combined.min.css">
<div ng-controller="myCtrl">
    <span call="best()" ></span>
</div>

JavaScript

var App = angular.module("myApp",[]);

App.controller("myCtrl",["$scope",function($scope){
    $scope.test = function(){
        console.log("Testing Going ON!!");
    };
    $scope.best = function(){
        console.log("Besting Going ON!!");
    };    
}]);

App.directive("call",function(){
    return function(scope,element,attrs){
        element.bind("mouseenter",function(){
            scope.$apply(attrs.call);
        });
        //console.log([scope,element,attrs]);
    }
});