question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

$scope.api returns undefined

See original GitHub issue

When I run the $scope.api functions in my code or in the plunkers, I get a type error:

TypeError: Cannot read property ‘refresh’ of undefined at Object.<anonymous> (http://localhost:9000/app/d3loader/d3loader.controller.js:21:17)

What am I doing wrong?

Here’s the code: HTML excerpt:

    <nvd3 options="options" data="data" api="api"></nvd3>

JavaScript:

var app = angular.module('plunker', ['nvd3']);

app.controller('MainCtrl', function($scope) {

    console.log('scope api:', $scope.api); //undefined
    $scope.api.refresh(); //Cannot read property 'refresh' of undefined

    $scope.options = {
            chart: {
                type: 'pieChart',
                height: 450,
                donut: true,
                x: function(d){return d.key;},
                y: function(d){return d.y;},
                showLabels: true,

                pie: {
                    startAngle: function(d) { return d.startAngle/2 -Math.PI/2 },
                    endAngle: function(d) { return d.endAngle/2 -Math.PI/2 }
                },
                transitionDuration: 500,
                legend: {
                    margin: {
                        top: 5,
                        right: 70,
                        bottom: 5,
                        left: 0
                    }
                }
            }

        };

        $scope.data = [
            {
                key: "One",
                y: 5
            },
            {
                key: "Two",
                y: 2
            },
            {
                key: "Three",
                y: 9
            },
            {
                key: "Four",
                y: 7
            },
            {
                key: "Five",
                y: 4
            },
            {
                key: "Six",
                y: 3
            },
            {
                key: "Seven",
                y: .5
            }
        ];
});

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:19 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
srujanrouthucommented, Aug 5, 2015

@owaaa: I kind of figured a work around. Stumbled on it, more like. When you set the api, instead of creating it as $scope.api, define it as $scope.xxx.api. This somehow worked for me. I’m not sure why though.

1reaction
kansorcommented, Jun 14, 2018

@srujanrouthu great suff… still useful…

Read more comments on GitHub >

github_iconTop Results From Across the Web

AngularJS scope values undefined but API is working fine
I don't get any error message, but while debugging Scope values are not binding it shows Undefined... Controller: $scope.companyModify = ...
Read more >
Why is my REST call undefined? - SharePoint Stack Exchange
A couple of reasons: AJAX calls are asynchronous. In your console.log statement, you care calling your GetCurrentUser function, ...
Read more >
angular.element().scope() return undefined in KendowWindow
I use these code to get the scopes behind both <span> and <input>, but the scope() result of span inside KendowWindow return undefined....
Read more >
undefined - JavaScript - MDN Web Docs - Mozilla
undefined is a property of the global object. That is, it is a variable in global scope. In all non-legacy browsers, undefined is...
Read more >
Re: Error: Scope undefined for API access: discounts_next.
There is definitely a misconfiguration or the library is outdated. There is no such scope discounts_next. Sergiu Svinarciuc | CTO @ visely.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found