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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:49:11+00:00 2026-06-13T07:49:11+00:00

I don’t understand how to watch multiple attributes at the same time in the

  • 0

I don’t understand how to watch multiple attributes at the same time in the link function, so I create an object with all the parameters and I watch for it. But I noticed that the attribute in the link function is a string and not an object so I’m using angular.fromJson(val).

All the example I found just use one parameter

Could you explain how to watch multiple attributes?

Thanks

EDIT:
I cannot use attrs parameter because I need to bind the attributes — i.e., they require interpolation. For example

<ul class="thumbnails">
    <li class="span3" ng-repeat="image in currentSizeInfo.images" >
       <upload-file info = "{{getInfo($index)}}" foo="foo$index" ></upload-file>
    </li>
</ul>

I think that I have to use $watch

link:function (scope, element, attrs ) {
    scope.$watch('info', function (val) {
    // if info is and foo is .... do all the stuff
    })
}
  • 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-13T07:49:12+00:00Added an answer on June 13, 2026 at 7:49 am

    I’m not sure I fully understand your question, so please correct me if I misunderstand. Are just want to pull values from multiple attributes on your directive? So say you have a HTML like this:

    <my-directive attr1="data1" attr2="data2" attr3="data3" />
    

    And you want to get the values of those different attributes? In the link function, you just use the attrs parameter. For example:

    link: function(scope, element, attrs) {
        var foo1 = attrs.attr1;
        var foo2 = attrs.attr2;
        var foo3 = attrs.attr3;
    }
    

    You can also use the scope property on the directive to automatically bind attributes to your scope. See their documentation on directives. So, something like this:

    scope: {
        attr1: '@',
        attr2: '@',
        attr3: '@'
    }
    

    And then those properties end up in your scope automatically. However, as I found out, those values aren’t always in the scope when you’d expect. So you can use the $watch function to do what you need with them. Something like:

    link: function(scope, element, attrs) {
        scope.$watch("attr1", function () {
             if (scope.attr1)
             {
                  //stuff with attr1
             }
        }
        scope.$watch("attr2", function () {
             if (scope.attr2)
             {
                  //stuff with attr2
             }
        }
        //....
    }
    

    If you need to use them all together at the same time, you could use a function for the first parameter of the $watch that returns a string that would be different once they are all there and then put your logic in the function that is the 2nd parameter. So something like this:

    link: function(scope, element, attrs) {
        scope.$watch(function () {
            if (scope.attr1 && scope.attr2 && scope.attr3)
            {
                return "allSet";
            }
            else
            {
                return "";
            }
        }, function (newVal) {
            if ("allSet" == newVal)
            {
                //do stuff with all the properties
            }
        });
    }
    

    If you’re wanting to bind objects into your scope, you can use ‘=’ instead of ‘@’. Another option is ‘&’ which evaluates a function in the parent scope. This is all explained in the directive documentation linked above.

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

Sidebar

Related Questions

Don't know whats exactly going on, but it's definitely killing my time for nothing.
Don't shoot me, but it's the first time I saw a usage of a
Don't understand this simple code: def main(): print (This program illustrates a chaotic function)
don't understand: in my controller: @json = User.all.to_gmaps4rails do |user| \Title\: \#{user.email}\ end in
don't know if the title describes anything about what I'm trying to say but
Don't ask me how but I'm in a situation where I have DCPs published
Don't really know how to formulate the title, but it should be pretty obvious
Don't know how to google for such, but is there a way to query
Don't know why but font is not displaying.Please help. CSS(in css folder): style.css: @font-face
Don't ask me why but I need to do the following: string ClassName =

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.