Example of Reading Scope in Custom DIrective
by Asif Sharif Shahid
HTML
<script src="http://code.angularjs.org/1.2.0-rc.2/angular.js"></script>
<div ng-app="testapp">
<div ng-controller="testCtrlr">
<div mdpagination > </div>
</div>
</div>
JavaScript
var MyDirectives = angular.module('testapp', []);
MyDirectives.controller('testCtrlr',['$scope', function($scope){
$scope.pages = 'PAGES!'
}]);
MyDirectives.directive("mdpagination", function(){
console.log('DIRECTIVE!');
return {
template: "<h1>BLAH!</h1>",
replace: true,
restrict: 'A',
scope: false, //default
link: function(scope, element, attrs){
console.log('in linking function');
console.dir(scope);
console.dir(element);
console.dir(attrs);
console.dir(scope.pages);
}
}
});