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
<d3-chart virtitems="vm.virtStats"></d3-chart>
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&utm_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
> <https://github.com/johnpapa/angular-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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.