Balkrishan Nagpal Balkrishan Nagpal - 1 year ago 89
Javascript Question

ReferenceError: function not defined

I am trying to invoke a javascript method. I am building the html at run time by string concatenation.

$scope.getRoute = function (isRouteFormValid) {
routingDemoPageService.executeService(serviceURL, 'admin', 'admin').then(function (response) {
function tryingOnceAgain() {

var markers = L.markerClusterGroup({
chunkedLoading: true

var geojsonLayer = L.geoJson(response, {
onEachFeature: function(feature, layer){

var UIDValue = (['uid'] !== null ?['uid'])) : '');

var popupContent = '<table>' +
'<tr><th scope="row"><a href="javascript:tryingOnceAgain()">Edit</a></th><td></td></tr>' +

'<tr><th scope="row">uid</th><td>' + UIDValue + '</td></tr></table>';


})['catch'](function (error) {



When i click on the link, which invokes tryingOnceAgain method, i am getting following error

ReferenceError: tryingOnceAgain is not defined

I am not sure why i am getting following error.

Can someone please provide any pointers what am i doing wrong.

Answer Source

javascript:tryingOnceAgain() is referenced to a function in the global scope but you defined tryingOnceAgain function inside function (response) { scope.

To fix that you have to move your tryingOnceAgain function to global scope.

Or just assign it to window object without changing physical place:

window.tryingOnceAgain = function() {...}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download