Answers.Body: <p>I usually do it in an extension. This allows me to enable/disable changes at will.</p>
  
  <ol>
  <li>Create an extension with Civix (eg com.example.myextension). </li>
  <li>Inside the extension folder create (eg [ext_dir]/com.example.myextension/js/) folder. </li>
  <li>Create your JS file in there (eg [ext_dir]/com.example.myextension/js/mychanges.js)</li>
  <li><p>In the main extension file (eg [ext_dir]/com.example.myextension/myextension.php) add this hook. I think its called on all pages and forms -- may have to use pageRun or alterContent.</p>
  
  <pre><code>function myextension_civicrm_alterTemplateFile($formName, &amp;$form, $context, &amp;$tplName) {
  
      $resource = CRM_Core_Resources::singleton();
  
      if ($formName=='theFormToEdit') {
          $resource-&gt;addScriptFile('com.example.myextension', 'js/mychanges.js');
      }
  }
  </code></pre></li>
  <li>Install and enable your extension.</li>
  </ol>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-05T07:44:09.723Z
Answers.Text: As I understand it, this will work for an Angular form when 'theFormToEdit' is 'Civi\Angular\Page\Main', but you'll end up with the resource being added to all angular forms (which may or may not be what you want).
Answers.UserDisplayName: michaelmcandrew
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-05T20:18:54.107Z
Answers.Text: I think the angularModules hook is new in the docs since I wrote this. It looks like a good alternative to my solution that would fix the issues you bring up. https://docs.civicrm.org/dev/en/master/hooks/hook_civicrm_angularModules/
Answers.UserDisplayName: David Hayes
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-04-28T17:48:02.857Z
Answers.LastActivityDate: 2016-04-28T17:48:02.857Z
Answers.UserDisplayName: David Hayes
Body: <p>I want to modify the behaviour of an Angular form.</p>
  
  <p>The answer to <a href="https://civicrm.stackexchange.com/questions/4700/how-do-i-modify-the-new-4-6-civimail-form">question 4700</a> tells me 'how' to do it (add some JavaScript), but I'm interested in 'where' to do it.</p>
  
  <p>If it was a PHP form I could use a hook. Should I use an extension?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-04-29T06:59:43.873Z
Comments.Text: Possible duplicate with http://civicrm.stackexchange.com/questions/9062/how-to-change-mailing-form
Comments.UserDisplayName: Philipp Michael
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-04-05T07:44:38.057Z
Comments.Text: Another good similar answer: http://civicrm.stackexchange.com/questions/10391/adding-dynamic-data-in-civimail-angular-template
Comments.UserDisplayName: michaelmcandrew
Tags: <extension><hooks><developer><angular>
Title: What is the mechanism for tailoring an Angular form?
ThreadText: # What is the mechanism for tailoring an Angular form?
  
  (Asked by: username_0 on 2016-04-22)
  
  I want to modify the behaviour of an Angular form.
  
  The answer to [question 4700](https://civicrm.stackexchange.com/questions/4700/how-do-i-modify-the-new-4-6-civimail-form) tells me 'how' to do it (add some JavaScript), but I'm interested in 'where' to do it.
  
  If it was a PHP form I could use a hook. Should I use an extension?
  
  **Tags:** extension, hooks, developer, angular
  
  > **Comments:**
  > **username_1**: Possible duplicate with http://civicrm.stackexchange.com/questions/9062/how-to-change-mailing-form  
  > **username_2**: Another good similar answer: http://civicrm.stackexchange.com/questions/10391/adding-dynamic-data-in-civimail-angular-template  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_3 on 2016-04-28. Score: 1
  
  I usually do it in an extension. This allows me to enable/disable changes at will.
  
  Create an extension with Civix (eg com.example.myextension). 
  Inside the extension folder create (eg [ext_dir]/com.example.myextension/js/) folder. 
  Create your JS file in there (eg [ext_dir]/com.example.myextension/js/mychanges.js)
  In the main extension file (eg [ext_dir]/com.example.myextension/myextension.php) add this hook. I think its called on all pages and forms -- may have to use pageRun or alterContent.
  function myextension_civicrm_alterTemplateFile($formName, &$form, $context, &$tplName) {
  
      $resource = CRM_Core_Resources::singleton();
  
      if ($formName=='theFormToEdit') {
          $resource->addScriptFile('com.example.myextension', 'js/mychanges.js');
      }
  }
  
  Install and enable your extension.
  
  > **Comments:**
  > **username_2**: As I understand it, this will work for an Angular form when 'theFormToEdit' is 'Civi\Angular\Page\Main', but you'll end up with the resource being added to all angular forms (which may or may not be what you want).  
  > **username_3**: I think the angularModules hook is new in the docs since I wrote this. It looks like a good alternative to my solution that would fix the issues you bring up. https://docs.civicrm.org/dev/en/master/hooks/hook_civicrm_angularModules/  
  
  ---
  
  