G.Mounika G.Mounika - 3 months ago 8
AngularJS Question

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

I want to use the value of

$scope.data.range
from controller.js in map.js.

This is my controller.js

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

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


How can I use this
$scope.data.range
in map.js which is a simple javascript file.

Answer

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.

Comments