Answers.Body: <p><code>selectedMail</code> is a function on the <code>route</code>´s <code>resolve</code> property, I believe you cannot inject it into another controller because the <code>controller</code> is instantiated in the route, but you can access the resolve property anywhere injecting the <code>$route</code> service like this:</p>
  
  <pre><code>...
  angular.module('crmMailing').controller('crmMailingRecurScheduleCtrl', function($scope, $filter, $route) {
    var mailing_id = $route.current.locals.selectedMail.id;
  ...
  </code></pre>
  
  <p>Alternatively the way your directives are defined, the scope value is default to <code>true</code>, therefore you should be able to access the parent scope like <code>var mailing_id = $scope.mailing.id;</code>, <code>mailing</code> is the object holding the mailing settings.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-18T17:36:50.883Z
Answers.Text: `$route.current.locals.selectedMail.id;` worked a treat. I could not get a call to console.log(mailing) to work from inside the new controller that I had defined. Where should I expect mailing to be defined?
Answers.UserDisplayName: michaelmcandrew
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-18T17:43:54.793Z
Answers.Text: Also, I realised that `mailing` was available in the template of the [`crmMailingRecurSchedule` directive](https://github.com/3sd/civicrm-recurring-mail/blob/master/ang/civicrm-recurring-mail.js#L40) that I created and that it can be passed through to the $scope method as a parameter. I'm not sure if this is what you meant, or if I am doing it backwards, but it did work :)
Answers.UserDisplayName: michaelmcandrew
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-18T17:48:33.450Z
Answers.Text: My fault, I meant `$scope.mailing.id`, I'll edit that
Answers.UserDisplayName: Andrei
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-18T17:58:05.963Z
Answers.Text: oh wow, sneaky. a `console.log($scope);console.log($scope.mailing);console.log($scope);` makes me realise that angular is somehow intercepting calls to "undefined" properties and pulling them from somewhere. I wonder where/how...
Answers.UserDisplayName: michaelmcandrew
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-18T18:07:46.140Z
Answers.Text: Some properties might be initially undefined, there might be a promise setting it, also `console.log()` is somehow out of angular's territory, that might be another reason? You can try using `$log.log()`, which is angular's service/ _native way_ to log stuff, just remember to inject it into your controller before using it
Answers.UserDisplayName: Andrei
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-18T18:12:54.970Z
Answers.Text: ok. thanks. fwiw for others stumbling here, $scope inheritance seems fairly core to angular, see for example https://www.undefinednull.com/2014/02/11/mastering-the-scope-of-a-directive-in-angularjs/ which has some good background on the subject.
Answers.UserDisplayName: michaelmcandrew
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-17T11:05:16.223Z
Answers.LastActivityDate: 2017-04-18T17:49:09.173Z
Answers.LastEditDate: 2017-04-18T17:49:09.173Z
Answers.UserDisplayName: Andrei
Body: <p>I've created a new angular controller </p>
  
  <pre><code>angular.module('crmMailing').controller('crmMailingRecurScheduleCtrl', function($scope, $filter) {
  </code></pre>
  
  <p>I'd like to have access to the selectedMail object that other controllers (the ones built with <code>.factory('crmMailingSimpleDirective'</code>) so I can use the ID in an API call but I don't have the chops to work out how to go about doing getting access.</p>
  
  <p>Adding selectedMail to the call back params didn't work.</p>
  
  <p>Defining the callback as EditMailingCtrl didn't work either.</p>
  
  <p>Help a noob out?!</p>
  
  <p><a href="https://github.com/3sd/civicrm-recurring-mail/blob/master/ang/civicrm-recurring-mail.js#L46" rel="nofollow noreferrer">Here is the code</a> in case you are interested in more context.</p>
  
Tags: <civimail><angular>
Title: Accessing selectedMail in a new controller
ThreadText: # Accessing selectedMail in a new controller
  
  (Asked by: username_0 on 2017-04-13)
  
  I've created a new angular controller
  
  ```
  angular.module('crmMailing').controller('crmMailingRecurScheduleCtrl', function($scope, $filter) {
  
  ```
  
  I'd like to have access to the selectedMail object that other controllers (the ones built with `.factory('crmMailingSimpleDirective'`) so I can use the ID in an API call but I don't have the chops to work out how to go about doing getting access.
  
  Adding selectedMail to the call back params didn't work.
  
  Defining the callback as EditMailingCtrl didn't work either.
  
  Help a noob out?!
  
  [Here is the code](https://github.com/3sd/civicrm-recurring-mail/blob/master/ang/civicrm-recurring-mail.js#L46) in case you are interested in more context.
  
  **Tags:** civimail, angular
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-04-17. Score: 1 | Accepted answer
  
  `selectedMail` is a function on the `route`´s `resolve` property, I believe you cannot inject it into another controller because the `controller` is instantiated in the route, but you can access the resolve property anywhere injecting the `$route` service like this:
  
  ```
  ...
  angular.module('crmMailing').controller('crmMailingRecurScheduleCtrl', function($scope, $filter, $route) {
    var mailing_id = $route.current.locals.selectedMail.id;
  ...
  
  ```
  
  Alternatively the way your directives are defined, the scope value is default to `true`, therefore you should be able to access the parent scope like `var mailing_id = $scope.mailing.id;`, `mailing` is the object holding the mailing settings.
  
  > **Comments:**
  > **username_0**: `$route.current.locals.selectedMail.id;` worked a treat. I could not get a call to console.log(mailing) to work from inside the new controller that I had defined. Where should I expect mailing to be defined?  
  > **username_0**: Also, I realised that `mailing` was available in the template of the [`crmMailingRecurSchedule` directive](https://github.com/3sd/civicrm-recurring-mail/blob/master/ang/civicrm-recurring-mail.js#L40) that I created and that it can be passed through to the $scope method as a parameter. I'm not sure if this is what you meant, or if I am doing it backwards, but it did work :)  
  > **username_1**: My fault, I meant `$scope.mailing.id`, I'll edit that  
  > **username_0**: oh wow, sneaky. a `console.log($scope);console.log($scope.mailing);console.log($scope);` makes me realise that angular is somehow intercepting calls to "undefined" properties and pulling them from somewhere. I wonder where/how...  
  > **username_1**: Some properties might be initially undefined, there might be a promise setting it, also `console.log()` is somehow out of angular's territory, that might be another reason? You can try using `$log.log()`, which is angular's service/ _native way_ to log stuff, just remember to inject it into your controller before using it  
  > **username_0**: ok. thanks. fwiw for others stumbling here, $scope inheritance seems fairly core to angular, see for example https://www.undefinednull.com/2014/02/11/mastering-the-scope-of-a-directive-in-angularjs/ which has some good background on the subject.  
  
  ---
  
  