Is it possible to call factory module from another javascript

I have two javascript files separately and I want to get one from the other. So, I created a factory module as shown below:

 var module = angular.module('test',[]);

 module.factory('$result', function() {
   var data = {something:"somewhere"};
   return data;
 });

and I want to call from another file. At the moment, I have stopped below:

 var module = angular.module('myApp', ['test']);

  module.controller('NearestController', function($test) {

    console.log(test);

  });

What part of me is doing wrong? help me and I'm new to angular

+4
source share
2 answers

It should be like that.

 var module = angular.module('test',[]);

 module.factory('Result', function() {
   var data = {something:"somewhere"};
   return data;
 });

You can call it that.

var module = angular.module('myApp', ['test']);

  module.controller('NearestController', function(Result) {

    console.log(Result);

  });

Hope this could be a job.

+2
source

As suggested comments, you enter your dependencies as parameters in your controller function:

 var module = angular.module('myApp', ['test']);

  module.controller('NearestController', function($result) {

    console.log(test);

  });
0
source

All Articles