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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:10:11+00:00 2026-06-18T01:10:11+00:00

I have a directive which loads a JSON file then uses that data to

  • 0

I have a directive which loads a JSON file then uses that data to create an HTML5 canvas drawing (i.e the json data holds things such as text, color, position). I also have a number of input fields (text, sliders, etc) that allow the user to manipulate the drawing. I see that I can either $watch each of these element or use ng-click and call a function – is there a recommended approach?

Some perhaps relevant notes:

  • The form element and the canvas are all part of the same directive template
  • The form elements react onchange so no submit button
  • Each of these form element value get checked, maybe converted then they modify the json string. I then call a refresh function which reloads my canvas with the new data.

It’s possible that I am approaching this the wrong way too…

  • 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-18T01:10:12+00:00Added an answer on June 18, 2026 at 1:10 am

    So, from what I understand there are some actions by user on some elements (within a directive) and you have to do something every time these events are fired.

    The intent of $watch is to ‘watch’ / do something every time a particular variable’s value changes. $scope.$watch('watchedVariable', onWatchedVariableChangedFn) where onWatchedVariableChangedFn is a function. This is triggered only when the value actually changes, irrespective of what causes the change.

    On the other hand, you can hook up event handlers to the markup attributes, like ng-click='onClickFn()'. These get fired from actions on the UI elements. [Also note ng-click will work only on clickable elements. You seem to have multiple elements (text, sliders, etc).]

    You might have to see what exactly can cause the change of these values / cause you to redraw your canvas and then decide which way you want to go.

    Edit : A third alternate you might want to consider is to fire events ($emit / $broadcast) and handle ($on) those events wherever applicable.

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

Sidebar

Related Questions

I have some code that loads a default configuration file and then allows users
I have created an AsyncTask that loads data from a website then when I
I have an aspx page that has a @Page directive which points to a
I have an IDL file that has a #pragma prefix directive, but whenever I
I have a JPanel which uses a BoxLayout in the X_AXIS direction. The problem
I have a page which displays a form that a logged-in user can use
I've downloaded a few networking apps (games) that have you log in, then take
I have a UIImageView which loads in images from the documents directory on the
I have an asp.net page which loads and writes values from a record to
I've got a webpage which reads an XML file and loads the contents into

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.