Reputation: 2243
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() {
alert('called.....');
}
var markers = L.markerClusterGroup({
showCoverageOnHover:false,
chunkedLoading: true
});
var geojsonLayer = L.geoJson(response, {
onEachFeature: function(feature, layer){
var UIDValue = (feature.properties['uid'] !== null ? Autolinker.link(String(feature.properties['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>';
layer.bindPopup(popupContent);
}
});
markers.addLayer(geojsonLayer);
$scope.map.addLayer(markers);
$scope.map.fitBounds(markers.getBounds());
})['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.
Upvotes: 0
Views: 3471
Reputation: 4659
Your function-definition for tryingOnceAgain()
exists only inside the function where it is defined, in this case $scope.getRoute()
.
This makes that only code inside $scope.getRoute()
can call tryingOnceAgain()
and it'll run.
You'll have to define tryingOnceAgain()
outside of $scope.getRoute()
or make it a public property and call it like that inside the HTML.
Upvotes: 1
Reputation: 3925
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() {...}
Upvotes: 2