G.Mounika G.Mounika - 1 year ago 57
AngularJS Question

How to pass data from controller.js to map.js?

I want to use the value of

from controller.js in map.js.

This is my controller.js

angular.module('starter.controllers', [])


How can I use this
in map.js which is a simple javascript file.

Answer Source

If your map.js has no related to Angular, you can use localStorage to keep your range.

So in your controller, inject $localStorage, and set the variable in the localStrorage:

.controller("LocController", function($scope, $rootScope, $localStorage){
    $scope.data.range = 5000;
    $localStorage.range = $scope.data.range;

And then in your map.js, get the localStorage by localStorage.getItem('range');. Here you can find de doc of MDN for Storage.