$scope.api returns undefined
See original GitHub issueWhen 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:
- Created 9 years ago
- Comments:19 (1 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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.
@srujanrouthu great suff… still useful…