What is the best way to be able to use an array declared outside of an angular controller, withing the angular controller?
first I declare an array:
var cars = ["Saab", "Volvo", "BMW"];
I also have an angular controller:
var myApp = angular.module('myApp', []);
myApp.controller('MyCtrl', function ($scope) {
});
I have tried:
Passing the variable through as reference in the controller:
var myApp = angular.module('myApp', []);
myApp.controller('MyCtrl', function ($scope, url) {
});
and simply trying to call the variable from within the controller:
var myApp = angular.module('myApp', []);
myApp.controller('MyCtrl', function ($scope) {
console.log(cars[1]);
});
However, neither have worked.
How do I achieve this?