H
H
HoHsi2015-10-15 15:10:24
JavaScript
HoHsi, 2015-10-15 15:10:24

How to pass variable from template to Angular $rootScope?

Good afternoon!
There was a need to pass a variable from the template to Angular's $rootScope

<script>
      var screens = "[
          'scr1', 
          'scr2', 
          'scr3'
      ]"
</script>

During HTML generation, JSON is generated from the array, which should then be used in Angular.
PS I know that you can send a JSON request to the server from Angular, but I would like to minimize the number of requests to the server

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
bromzh, 2015-10-15
@HoHsi

I would like to minimize the number of requests to the server

So don't send too many, what's the problem? You create a service, in it a function that will load data, you call this function in the controller.
UPD
If the site is already generated from the outside, then you can do the same as the angular-templatecache plugin does for build systems: generate code that puts this data into a constant:
angular.module('app', [зависимости]); // это ты пишешь сам

// А это должен генерировать сам генератор:
angular.module('app').constant('screens', { 
а сюда вставлять сгенерированные данные в каком-то формате
});

Well, in the angular code, use this constant for its intended purpose.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question