Invoke a function passing arguments within $ Scope does not work

0

I have a function in a file called "mapHelper.js" responsible for adding popups to a map:

     function writeMarker(x,y,msg) {
     var muxiCoordinates = [x,y];
     var muxiMarkerMessage = msg;
     L.marker(muxiCoordinates).addTo(map).bindPopup(muxiMarkerMessage).openPopup();
     }

A controller that lets you read data from the database to $ scope.markers. The data is a list of coordinates and messages "x, y, msg"

angular.module("app",[]);
angular.module("app").controller("appCtrl",function($scope,$http){
    $http.get('/markers').then(function (res) {
        console.log("Got the data");
        $scope.markers=res.data;
    });
});

The question is: how to invoke this function by passing arguments within $ Scope?

I thought of something like:

    div(ng-repeat="marker in markers")
        script.
            writeMarker({{marker.x}},{{marker.y}},{{marker.msg}});

but does not work.

    
asked by anonymous 29.08.2017 / 21:14

1 answer

1

If your intention is to display exactly when the $ http return from the angle, you can go through the same response.

angular.module("app",[]);
angular.module("app").controller("appCtrl",function($scope,$http){
    $http.get('/markers').then(function (res) {
        console.log("Got the data");
        for(var i = 0; i < resp.data.length; i++){
            var data = resp.data[i];
            writeMarker(data.x,data.y,data.msg);
        }
    });
});

Now, if you want to dynamically use this javascript function, you can pass the javascript function to a scope of the angle, and then use with ng-click or something like the one you intended to do: / p>

$scope.writeMarker = writeMarker;
    
29.08.2017 / 21:23