AngularJS service in separate file

前端 未结 3 897
故里飘歌
故里飘歌 2021-02-04 17:01

My app.js contains

var app = angular.module(\'myApp\', []).
config([\'$routeProvider\', function ($routeProvider, $http) {
    ...
}]);

Servic

3条回答
  •  春和景丽
    2021-02-04 17:34

    Just as an added clarification on Brian's answer, if you wanted to still have your code call MyService.addNums you could use the following:

    app.service('MyService', function() {
        var result = {};
        result.addNums = function (text) {
            return text + "123";
        };
    
        return result;
    });
    

    Then you could still use

    MyService.addNums("abc");
    

    if you wanted to do so.  

提交回复
热议问题