The function below defines the variable in the root directory.
function MyCtrl($scope, $rootScope) { $rootScope.buttons = [{href: '#/students', icon:'icon-ok'}, {href: '#/students', icon:'icon-remove'}, {href: '#/students/new', icon:'icon-plus'}]; } MyCtrl.$inject = ['$scope', '$rootScope'];
The html in the directive below depends on the variable in the root crops -
angular.module('btnbar.directive', []). directive("btnBar", function(){ return { restrict: 'E', scope :{}, controller: function($scope, $element,$rootScope) { }, template:'<div class="btn-toolbar">' + '<a class="btn" ng-repeat="b in buttons" href={{b.href}}>' + '<i class={{b.icon}}></i></a></div>', replace:true } });
However, the above code does not work. It works if I directly define var "buttons" in the scope.
angularjs angularjs-scope
murtaza52 Dec 15 '12 at 18:51 2012-12-15 18:51
source share