For example there is a file service.js there is a file app.js

app.js:

var app = angular.module('myApp'); app.controller('MainCtrl', function(myService,$scope){ $scope.value = myService.value; }); 

service.js

 app.factory('myService', function(){ return{ value: 1 } }); 

How to physically link these files so that the service was visible from the controller (since in this form the service from the controller is not available, it gives an error). Is it necessary to use collectors, or is it done somehow differently "automatically")) sorry for the children's question. Thank!

  • What mistake? Are you in service.js angular.module ('myApp') Connect? - Yaroslav Zaika
  • If there is a file in which the myApp module is created , then in this case it is enough to plug in the service.js html after app.js and everything will work. If there is no such file, then the error will be when executing app.js - about the impossibility of getting a module. - Grundy
  • Thanks for the answer, yes, I really didn’t connect to html, and it’s normal to connect all parts of js files to html, is it possible to make the main app.js connect to html, and everything else is bind without any hardcode in <head> < / head> - Alexey Antonovich
  • @AlexeyAntonovich, with an angular, is problematic. You can use different collectors who will put everything into one file, but this is not the same as loading files on request - Grundy

1 answer 1

You need to use gulp or webpack for this .