// use factory angular.module('YourAppName') .factory('YourFuncName', function() { return function() { // your function code here } }); // use service angualr.module('YourAppName') .service('myUtils',function() { this.yourFuncName = function() { // your function code here } })
For the situation in the screenshot
angular.module('YourAppName') .factory('YourFuncName', function() { return function($scope) { return function(modal) { // Use $scope Here } } }); // 使用时 somthing.then(yourFuncName($scope))
Best to use
service
或者factory
For the situation in the screenshot