I'm using restangular to call external API. The GET request works only if I remove the single quotes from controller. Although, when I try to add an angular chart that fails, unless I add quotes back. So, one or the other works depending on if added or not. I need both to work so can use data from API for chart. Additionally, I'm not seeing any errors in browsers with or without the quotes.
This is partial app.js
var app = angular.module('mymod', ['ngRoute', 'ngResource', 'ui.bootstrap', 'chart.js', 'restangular'])
.config(function($routeProvider, RestangularProvider) {
$routeProvider
.when('/', {
templateUrl: 'app/main/main.html',
controller: MainCtrl // <--- This is what I'm referring to
})
.otherwise({
redirectTo: '/'
});
// Set base url
RestangularProvider.setBaseUrl('https://something.com/api/v1');
// Auth details
RestangularProvider.setDefaultHeaders({
'Authorization': 'Token token=mytoken',
'Content-Type': 'application/json',
});
// Format
RestangularProvider.setRequestSuffix('.json');
// Data extractor
RestangularProvider.setResponseExtractor(function(response, operation) {
return response.incidents;
});
});
// Graph Example
app.controller('MainCtrl', function($scope) {
$scope.labels = ["Download Sales", "In-Store Sales", "Mail-Order Sales"];
$scope.data = [300, 500, 100];
});
I added 'use strict'; to top of app.js and am now seeing this error: ReferenceError: i is not defined.
Which references the i in for loop below.
$scope.update = function(pages) {
for (i = 0; i < pages; i++) {
Restangular.all("incidents").getList({offset:25 * i, sort_by: "created_on:desc"})
.then(function(result) {
Array.prototype.push.apply($scope.incidents,result);
})
}
};
Also, I've been utilizing code example noted below and found a couple problems with it that i've fixed, but I'm new to Angular, so it's been difficult. reference: code example
'MainCtrl'for sure..error: ReferenceError: i is not defined: you did not declareias avar? should be, e.g.for (var i =0; i < pages; i++)