0

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.

3 Answers 3

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

I guess map.js comes under the same angular.module('starter.controllers', []), and if you dont want to go for sessions , you could use a service or factory. Else you could use localstorage or session storage

2 Comments

In my map.js file there is no angular related code. controller.js and map.js are two files under a folder.
still you can go for localstorage i think
0

I am not sure I can give a full solution since don't know how map.js is structured but you could, for example, add a function within the map.js like setDataRange(dataRange); and access this from the controller. Or in general access and update anything you want from the controller (provided you have included the map.js script before the controller.js). E.g. $scope.map = new Map(); $scope.map.range = .... etc. Hope this helps! (localstorage as mentioned could be a good solution also, but it all depends on what you want to do)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.