Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9061163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:24:57+00:00 2026-06-16T15:24:57+00:00

Normally in all examples/source code of AngularJS modifications of scope is done in controllers.

  • 0

Normally in all examples/source code of AngularJS modifications of scope is done in controllers. In my directive I need to get some information from another directive (or it’s scope) and put it into scope (so visible in template of directive). As this information is common for all instances of this directive, using scope binding does not sound good for me.

So the only solution I found is to modify instance scope in linking function:

link: function(scope, element, attr, parentCtrl) {      
  scope.data = parentCtrl.someData;      
}

This solution works. Plnkr example

The question: Is it ok according to AngularJS philosophy/style to modify scope in linking function or there is another solution?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T15:24:58+00:00Added an answer on June 16, 2026 at 3:24 pm

    Since you are creating isolate scopes in your directives (in your example plnkr), and you want to allow for parents to be ‘somewhere’ in the scope hierarchy (according to your comment to @MathewBerg), I believe your only option is to use the linking function to modify the scope.

    (I suppose you could define methods on your MainCtrl that only the child directives should call, but enforcing that would be messy and break encapsulation).

    So, to echo what @MathewBerg already said, yes, modify the scope in the directive/linking function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Today I browsed some source code (it was an example file explaining the use
Normally we all do use using System.Linq; and using System.Data.Linq; for example on the
Normally all the document related to an iOS application are stored in a document
Long introduction: Normally all data necessary for my web application are stored in session
I'm doing this query: SomeObject.objects.annotate(something=Avg('something')).order_by(something).all() I normally have an aggregate field in my model
Normally you use Form.Visible to check if Window is visible at all. But sometimes
I normally program in C++, so all this DataSource/DataSet/Binding stuff is confusing the hell
I'm trying to delete all rows in a table using Castle ActiveRecord. Normally, I
Why running debug doesn't build all selected project in the active configuration? Normally I've
ALL, is there any solution to get the number of opened files in my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.