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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T23:44:35+00:00 2026-06-18T23:44:35+00:00

I know that both Watchers and Observers are computed as soon as something in

  • 0

I know that both Watchers and Observers are computed as soon as something in $scope changes in AngularJS. But couldn’t understand what exactly is the difference between the two.

My initial understanding is that Observers are computed for angular expressions which are conditions on the HTML side where as Watchers executed when $scope.$watch() function is executed. Am I thinking properly?

  • 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-18T23:44:36+00:00Added an answer on June 18, 2026 at 11:44 pm

    $observe() is a method on the Attributes object, and as such, it can only be used to observe/watch the value change of a DOM attribute. It is only used/called inside directives. Use $observe when you need to observe/watch a DOM attribute that contains interpolation (i.e., {{}}’s).

    E.g., attr1="Name: {{name}}", then in a directive: attrs.$observe('attr1', ...).

    (If you try scope.$watch(attrs.attr1, ...) it won’t work because of the {{}}s — you’ll get undefined.) Use $watch for everything else.

    $watch() is more complicated. It can observe/watch an “expression”, where the expression can be either a function or a string. If the expression is a string, it is $parse‘d (i.e., evaluated as an Angular expression) into a function. (It is this function that is called every digest cycle.) The string expression can not contain {{}}’s. $watch is a method on the Scope object, so it can be used/called wherever you have access to a scope object, hence in

    • a controller — any controller — one created via ng-view, ng-controller, or a directive controller
    • a linking function in a directive, since this has access to a scope as well

    Because strings are evaluated as Angular expressions, $watch is often used when you want to observe/watch a model/scope property. E.g., attr1="myModel.some_prop", then in a controller or link function: scope.$watch('myModel.some_prop', ...) or scope.$watch(attrs.attr1, ...) (or scope.$watch(attrs['attr1'], ...)).

    (If you try attrs.$observe('attr1') you’ll get the string myModel.some_prop, which is probably not what you want.)

    As discussed in comments on @PrimosK’s answer, all $observes and $watches are checked every digest cycle.

    Directives with isolate scopes are more complicated. If the ‘@’ syntax is used, you can $observe or $watch a DOM attribute that contains interpolation (i.e., {{}}’s). (The reason it works with $watch is because the ‘@’ syntax does the interpolation for us, hence $watch sees a string without {{}}’s.) To make it easier to remember which to use when, I suggest using $observe for this case also.

    To help test all of this, I wrote a Plunker that defines two directives. One (d1) does not create a new scope, the other (d2) creates an isolate scope. Each directive has the same six attributes. Each attribute is both $observe’d and $watch’ed.

    <div d1 attr1="{{prop1}}-test" attr2="prop2" attr3="33" attr4="'a_string'"
            attr5="a_string" attr6="{{1+aNumber}}"></div>
    

    Look at the console log to see the differences between $observe and $watch in the linking function. Then click the link and see which $observes and $watches are triggered by the property changes made by the click handler.

    Notice that when the link function runs, any attributes that contain {{}}’s are not evaluated yet (so if you try to examine the attributes, you’ll get undefined). The only way to see the interpolated values is to use $observe (or $watch if using an isolate scope with ‘@’). Therefore, getting the values of these attributes is an asynchronous operation. (And this is why we need the $observe and $watch functions.)

    Sometimes you don’t need $observe or $watch. E.g., if your attribute contains a number or a boolean (not a string), just evaluate it once: attr1="22", then in, say, your linking function: var count = scope.$eval(attrs.attr1). If it is just a constant string – attr1="my string" – then just use attrs.attr1 in your directive (no need for $eval()).

    See also Vojta’s google group post about $watch expressions.

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

Sidebar

Related Questions

I know that both is on off-chip DRAM and cached. But which is faster
I know that both these databases are better for different scenarios but in terms
I just came to know that it's possible to record call voice (both incoming
We all know that a hash table has O(1) time for both inserts and
For input text files, I know that .seek and .tell both operate with bytes,
I'm trying to compile a project that uses both libjpeg and libpng. I know
I know that Phonegap has an event for back button, but it's only available
I know that this sort of question has been asked here before, but still
I know that Java have its own garbage collection, but sometimes I want to
This a basic doubt, but I wanted to know that if establish two TCP

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.