g00fy
g00fy

Reputation: 4737

AngularJS what does locals in directive stand for

AFAIK this is not documented, but I found in angular source a locals attribute in a directive example:

angular.module('transclude', [])
          .directive('pane', function(){
             return {
               restrict: 'E',
               transclude: true,
               scope: 'isolate',
               locals: { title:'bind' },
               template: '<div style="border: 1px solid black;">' +
                           '<div style="background-color: gray">{{title}}</div>' +
                           '<div ng-transclude></div>' +
                         '</div>'
             };
         });

What does it do? How can I use it?

EDIT

to be more precise:

How can I access locals from directive's controller or linking function?

How can I dynamicly change locals from directive's controller or linking function?

Can I use locals in every directive, or does it have to be a directive with a transclude=true ?

Upvotes: 4

Views: 2729

Answers (2)

g00fy
g00fy

Reputation: 4737

I just want to close this question. So the answer is like @ArunPJohny said

@param {Object=} locals (Optional object).

If preset then any argument names are read from this object first, before the $injector is consulted

Upvotes: 1

Mark Rajcok
Mark Rajcok

Reputation: 364727

The example code is on the ngTransclude page, inside the script.js tab.

I believe this is just the older syntax (which still seems to work). The newer syntax would replace

scope: 'isolate',
locals: { title:'bind' },

with

scope: { title: '@' },

Upvotes: 1

Related Questions