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 9172753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:25:34+00:00 2026-06-17T16:25:34+00:00

Please see the example here foodMeApp.directive(‘fmRating’, function() { return { restrict: ‘E’, scope: {

  • 0

Please see the example here

foodMeApp.directive('fmRating', function() {
  return {
    restrict: 'E',
    scope: {
      symbol: '@',
      max: '@',
      readonly: '@'
    },
    require: 'ngModel',
    link: function(scope, element, attrs, ngModel) {

      attrs.max = scope.max = parseInt(scope.max || 5, 10);
...

Angular needs symbol , max, readonly to be defined in the isolated scope object to access it from parent scope.

it is used here

<fm-rating ng-model="$parent.restaurant.price" symbol="$" readonly="true"></fm-rating>

So, what is the purpose of attrs? Can’t one access all the attributes passed through attrs. Why can’t one access value of max as attrs.max instead of scope.max

Why assign back like attrs.max = scope.max ?

Since this app is written by Angular authors, I expect a reason.

thanks.

  • 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-17T16:25:35+00:00Added an answer on June 17, 2026 at 4:25 pm

    what is the purpose of attrs?

    Attributes defined on the same element as your directive have a few purposes:

    1. They are the only way to pass information into a directive that uses an isolate scope. Since the directive isolate scope doesn’t prototypically inherit from the parent scope, we need a way to specify what we want to pass to the isolate scope. ‘@’, ‘=’, and ‘&’ in the “object hash” therefore each require an attribute to specify what data/information is being passed.
    2. They serve as an inter-directive communication mechanism. (E.g., Managing communication between independent AngularJS directives independently)
    3. They normalize the attribute names.

    Can’t one access all the attributes passed through attrs?

    Yes you can, but

    1. you will not have any data binding.

      ‘@’ sets up one-way “string” databinding (parent scope → directive isolate scope) With @ the value you see/get in the directive is always a string, so don’t use this if you’re trying to pass an object to your directive.

      ‘=’ sets up two-way databinding (parent scope ↔ directive isolate scope).

      Without databinding, your directive can’t $watch or $observe model/data changes automatically.
    2. attribute values with {{}}s will cause you problems, since they will not be interpolated.

      Suppose we have <my-directive name="My name is {{name}}"> and the parent scope has $scope.name='Mark'. Then, inside the linking function, console.log(attrs.name) results in undefined.

      If name is an isolate scope property defined with ‘@’, then attrs.$observe('name', function(val) { console.log(val) }) results in My name is Mark. (Note that inside the linking function, $observe() must be used to get the interpolated value.)

    Why can’t one access value of max as attrs.max instead of scope.max

    answered above

    Why assign back like attrs.max = scope.max ?

    The only reason I can think of for doing this is in case some other directive needs to see this attribute/value (i.e., inter-directive communication). However, the other directive would need to run after this directive for this to work (which can be controlled somewhat with the priority directive setting).

    Summary: in a directive with an isolate scope, normally you don’t want to use attrs. (I suppose it could be a way to send initialization data/values into a directive — i.e., if you don’t need databinding for these values and you don’t need interpolation.)

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

Sidebar

Related Questions

Please see here for example: ( banners > dizzee rascal > see more+ )
Please see my script here: LIVE EXAMPLE There is a unintelligible behavior which I
everyone. Please see example below. I'd like to supply a string to 'schedule_action' method
Please see this example: if (strlen($_SESSION['userDetails']['THISNAME']) == 0) { $_SESSION['userDetails'][''.$THISNAME.'Error'] = autofocus; include $docRoot/html/forms/reg/user_info.html.php;
I having trouble in my sql query .Please see my example As u see,
Please see demo here: http://jsfiddle.net/mA6qm/1/ (expand console) Why aren't events being sent or received
Please see here , at the end of the post, the 70px author image
Please see an example of my code below: CODE UPDATED public class ScrollableCheckboxList {
Please see the example . I provided height:150px; overflow:auto; to all <td> tags. On
I'm refering to this great example: See here I'm getting the following errors and

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.