To utilize the $scope.urls
parameter in your AngularJS application, you must initialize raven within it. However, the approach you attempted is not viable:
var myApp = angular.module('myApp',[]);
myApp.controller('MyCtrl', function ($scope) {
$scope.urls = ['https://test1.com/', 'https://test2.com'];
Raven.config('___PUBLIC_DSN___', {
release: '1.3.0',
whitelistUrls: $scope.urls,
}).install()
});
Dynamic Script Appending Solution:
An alternative method is to dynamically append the script to your DOM using a directive, as demonstrated in this demo fiddle:
View
<div ng-controller="MyCtrl">
<span>Right after here:</span>
<div my-append-script url-data="urls"></div>
</div>
AngularJS Application
var myApp = angular.module('myApp',[]);
myApp.controller('MyCtrl', function ($scope) {
$scope.urls = ['https://test1.com/', 'https://test2.com'];
});
myApp.directive('myAppendScript', function () {
return {
restrit: 'A',
scope: {
urlData: '=urlData'
},
link: function (scope, element, attrs) {
var wrapArray = '';
angular.forEach(scope.urlData, function (item, index) {
if (index !== 0 ) {
wrapArray += ','+"'"+item+"'";
} else {
wrapArray += "'"+item+"'";
}
});
wrapArray = '['+wrapArray+']';
var script = document.createElement('script');
script.setAttribute('type', 'text/javascript');
script.innerHTML = `
console.log(`+wrapArray+`);
Raven.config('___PUBLIC_DSN___', {
release: '1.3.0',
whitelistUrls: `+wrapArray+`,
}).install()`;
element.append(script);
}
}
});