[AngularJS] Re: How to use data from controller in directive

2017-06-13 Thread Tito
ok moving away from $scope immediately and going for components.

On Monday, June 12, 2017 at 9:20:13 PM UTC-7, Sander Elias wrote:
>
> Hi Tito,
>
> There is your answer al along. However, you still shouldn't be using 
> $scope 
> .
>  
> In this case, that would have saved you hours. Using components 
> helps. 
>
> Regards
> Sander
>

-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to angular+unsubscr...@googlegroups.com.
To post to this group, send email to angular@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.


[AngularJS] Re: How to use data from controller in directive

2017-06-12 Thread Sander Elias
Hi Tito,

There is your answer al along. However, you still shouldn't be using $scope 
.
 
In this case, that would have saved you hours. Using components 
helps. 

Regards
Sander

-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to angular+unsubscr...@googlegroups.com.
To post to this group, send email to angular@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.


[AngularJS] Re: How to use data from controller in directive

2017-06-12 Thread Tito
I notice this 





On Friday, June 9, 2017 at 8:25:14 PM UTC-7, Sander Elias wrote:
>
> Hi Tito,
>
> Do this in your dashboard controller. Don't use the link function, it is 
> of very limited use.
>
> function Dashboard() {
> const vm = this;
>
> vm.$onInit = () => {
> console.log(vm);
> }
> }
>
>
> Regards
> Sander
>

-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to angular+unsubscr...@googlegroups.com.
To post to this group, send email to angular@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.


[AngularJS] Re: How to use data from controller in directive

2017-06-12 Thread Tito
I tried more tweaks without using $onInit and I notice the following when 
doing
console.log('Directive Controller vm', scope.vmd);
Why cant I access virtStats or how can I access that. I tried all kinds of 
things.



On Saturday, June 10, 2017 at 9:11:01 AM UTC-7, Tito wrote:
>
> Ok I will try that, 
>
> The link function is where I am doing bulk of my graphing like the 
> following
>
> https://bl.ocks.org/mbostock/3887051
>
>
>
> On Friday, June 9, 2017 at 8:25:14 PM UTC-7, Sander Elias wrote:
>>
>> Hi Tito,
>>
>> Do this in your dashboard controller. Don't use the link function, it is 
>> of very limited use.
>>
>> function Dashboard() {
>> const vm = this;
>>
>> vm.$onInit = () => {
>> console.log(vm);
>> }
>> }
>>
>>
>> Regards
>> Sander
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to angular+unsubscr...@googlegroups.com.
To post to this group, send email to angular@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.


[AngularJS] Re: How to use data from controller in directive

2017-06-12 Thread Tito
This is so odd. without adding $onInit. I do the following 
console.log('Directive Controller vm', scope.vm);

   1. and I see this! I want that virtStats, but I cant access it via 
   scope.vm.virtStats. This is weird. I am sure this is basic javascript 
   issue not angular
   2. Dashboard {deptvirts: Array(0), virtStats: Array(0), title: 
   "Dashboard", virtitems: Array(0)}
  1. deptvirts:Array(61)
  2. rmas:Array(0)
  3. title:"Dashboard"
  4. virtStats:Array(9)
  5. virtitems:Array(9)
  6. __proto__:Object
   

On Friday, June 9, 2017 at 8:25:14 PM UTC-7, Sander Elias wrote:
>
> Hi Tito,
>
> Do this in your dashboard controller. Don't use the link function, it is 
> of very limited use.
>
> function Dashboard() {
> const vm = this;
>
> vm.$onInit = () => {
> console.log(vm);
> }
> }
>
>
> Regards
> Sander
>

-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to angular+unsubscr...@googlegroups.com.
To post to this group, send email to angular@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.


[AngularJS] Re: How to use data from controller in directive

2017-06-10 Thread Tito
Ok I will try that, 

The link function is where I am doing bulk of my graphing like the following

https://bl.ocks.org/mbostock/3887051



On Friday, June 9, 2017 at 8:25:14 PM UTC-7, Sander Elias wrote:
>
> Hi Tito,
>
> Do this in your dashboard controller. Don't use the link function, it is 
> of very limited use.
>
> function Dashboard() {
> const vm = this;
>
> vm.$onInit = () => {
> console.log(vm);
> }
> }
>
>
> Regards
> Sander
>

-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to angular+unsubscr...@googlegroups.com.
To post to this group, send email to angular@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.


[AngularJS] Re: How to use data from controller in directive

2017-06-09 Thread Sander Elias
Hi Tito,

Do this in your dashboard controller. Don't use the link function, it is of 
very limited use.

function Dashboard() {
const vm = this;

vm.$onInit = () => {
console.log(vm);
}
}


Regards
Sander

-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to angular+unsubscr...@googlegroups.com.
To post to this group, send email to angular@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.


[AngularJS] Re: How to use data from controller in directive

2017-06-09 Thread Tito
Ok read and re-read and I am still not wrapping my head around this. it has 
been a long week and I was hoping I would leave work with a 3 point shot 
but I guess a layup is good enough in that I have learned a lot.
Using exactly the style guide, in my dashboard folder I have 

1.My dashboard.html that says


2. My dashboard.controller.js  (for now my directive is in there, I will 
break it out (baby steps)

(function () {
'use strict';

angular
.module('app.dashboard')
.controller('Dashboard', Dashboard)
//http://phloxblog.in/angulard3/start.html?utm_source=tuicool_medium=referral#.WTgbfuvythE
//http://bl.ocks.org/biovisualize/5372077
//http://www.ng-newsletter.com/posts/d3-on-angular.html
.directive('d3Chart', buildChart);

function buildChart() {
var directive = {
restrict: 'EA',
scope: {
virtitems: '=virtStats'
},
link: linkFunc,
controller: Dashboard,
// note: This would be 'ExampleController' (the exported controller name, 
as string)
// if referring to a defined controller in its separate file.
controllerAs: 'vm',
bindToController: true // because the scope is isolated
};

return directive;
function linkFunc(scope, el, attr, ctrl) {
console.log('scope.vm.virtitems', scope.vm.virtitems); //says undefined. 
Going bonkers here! HELP!
}

Dashboard.$inject = ['$state', '$scope', 'dataservice', 'logger'];

function Dashboard($state, $scope, dataservice, logger) {
var vm = this;
vm.virtStats = [
{
"folder": "DR",
"Active": 0,
"Idle": 0,
"PoweredOff": 121
},
{
"folder": "ILT",
"Active": 10,
"Idle": 11,
"PoweredOff": 2
},
{
"folder": "IT",
"Active": 122,
"Idle": 13,
"PoweredOff": 22
},
{
"folder": "Test",
"Active": 0,
"Idle": 0,
"PoweredOff": 1
}]



On Wednesday, June 7, 2017 at 9:47:38 PM UTC-7, Sander Elias wrote:
>
> Hi Tito,
>
> 1. don't use replace unless you really have no other option. This has been 
> deprecated for ages!
> 2. try to avoid $scope as much as possible, read the styleguide 
> !
> 3. if you use the controlleAs property on your directive, you can grab 
> this from its parent.
> 4. switch to .components This makes your life a lot easier.
>
> Regards
> Sander
>

-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to angular+unsubscr...@googlegroups.com.
To post to this group, send email to angular@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.


[AngularJS] Re: How to use data from controller in directive

2017-06-08 Thread Tito
wow! Thank you so much Sander!

This helped out big time. I had totally forgotten this gem of info for 
directives and much more!

On Wednesday, June 7, 2017 at 9:47:38 PM UTC-7, Sander Elias wrote:
>
> Hi Tito,
>
> 1. don't use replace unless you really have no other option. This has been 
> deprecated for ages!
> 2. try to avoid $scope as much as possible, read the styleguide 
> !
> 3. if you use the controlleAs property on your directive, you can grab 
> this from its parent.
> 4. switch to .components This makes your life a lot easier.
>
> Regards
> Sander
>

-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to angular+unsubscr...@googlegroups.com.
To post to this group, send email to angular@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.


[AngularJS] Re: How to use data from controller in directive

2017-06-07 Thread Sander Elias
Hi Tito,

1. don't use replace unless you really have no other option. This has been 
deprecated for ages!
2. try to avoid $scope as much as possible, read the styleguide 
!
3. if you use the controlleAs property on your directive, you can grab this 
from its parent.
4. switch to .components This makes your life a lot easier.

Regards
Sander

-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to angular+unsubscr...@googlegroups.com.
To post to this group, send email to angular@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.